Jun 23
This script is a little more elaborate and has the feel of a professional Perl program called findcore. The contents of findcore are as follows:
#!/usr/bin/perl
print “Looking for core files…\n”;
#find command looks from / for real files (no dirs, symlinks, etc.)
#named core
@core = `find / -type f -name core 2>/dev/null`;
chop (@core);
$num = @core;
if (@core) {
if ($num == 1) {
print “Found $num core file… removing…\n”;
} else {
print “Found $num core files… removing…\n”;
}
foreach $file (@core) {
# if we have write (-w) permission for file, we can delete it
if (-w $file) {
system(”rm -rf $file”);
print “Deleted $file.\n”;
} else {
print “You do not have permission to delete $file!\n”;
}
}
} else {
print “No core files found!\n”;
}
exit(0);
This script is relatively simple to write and use. Simply give it execute permissions and run it like this
chmod 755 findcore
./findcore
Jun 13
http://www.cplicensing.net/scripts.php
perl process listening on Port 80 and 443
—————————————–
root@server204: lsof -i TCP:80 | grep perl | awk ‘{print $2}’ |xargs kill -9
root@server204: lsof -i TCP:443 | grep perl | awk ‘{print $2}’ |xargs kill -9
Apache Down
———–
a)Semaphore issue–run this command
ipcs -s | grep nobody | perl -e ‘while () { @a=split(/\s+/); print `ipcrm sem $a[1]`}’
b)Port 80 and 443 running for another process.
lsof -i TCP:80 | awk ‘{print $2}’ |xargs kill -9
lsof -i TCP:443 | awk ‘{print $2}’ |xargs kill -9
start apache.
To change IP address of DNS zone
###################################
#!/bin/bash
for i in `cat /var/named/zones`
do
perl -pi -e ’s///’ $i
done
####################################
Find Sync attack
netstat -pant|grep SYN|awk ‘{print $5}’|sort|uniq -c|sort -n|grep -v 127.0.0.1|cut -d: -f1
Kill Zombie process
ps -ef | grep mailnull | grep -v grep | awk ‘{print “kill -9″, $2}’ | sh
replace mailnull with particular proces name which has zombie
Jun 13
Please use the following code to update files with perl.
1)perl -pi -e ’s/wordToFind/replaceWithThisWord/g’ *.fileExtension
eg:
create a test.txt file with contents niyas
Then execute
perl -pi -e ’s/niyas/pratheesh/g’ test.txt
Also you can take the backup of the original file using the command
2)perl -pi.bak -e ’s/niyas/pratheesh/g’ test.txt
3)replace current_text final_text –filename
See the change
Jun 13
1 . Login to the server as root
# vi /root/loadalert
2. And the below script
——————————————-
#!/bin/bash
#Wednesday, December 06 2006
EMAIL=”test@gmail.com”
EMAIL1=”test@yahoo.com”
SUBJECT=”$(hostname) load is”
TEMPFILE=”/tmp/$(hostname)”
echo “Load average has crossed the limits…” >> $TEMPFILE
echo “Hostname: $(hostname)” >> $TEMPFILE
echo “Local Date & Time : $(date)” >> $TEMPFILE
echo “| Uptime status: |” >> $TEMPFILE
echo “——————” >> $TEMPFILE
/usr/bin/uptime >> $TEMPFILE
echo “——————” >> $TEMPFILE
echo “| Top 20 CPU consuming processes: |” >> $TEMPFILE
ps aux | head -1 >> $TEMPFILE
ps aux –no-headers | sort -rn +2 | head -20 >> $TEMPFILE
echo “| Top 10 memory-consuming processes: |” >> $TEMPFILE
ps aux –no-headers| sort -rn +3 | head >> $TEMPFILE
echo “—————————” >> $TEMPFILE
echo “| Memory and Swap status: |” >> $TEMPFILE
/usr/bin/free -m >> $TEMPFILE
echo “——————————” >> $TEMPFILE
echo “| Disk Space information: |” >> $TEMPFILE
echo “—————————” >> $TEMPFILE
/bin/df -h >> $TEMPFILE
echo “——THE END—————-” >> $TEMPFILE
L05=”$(uptime|awk ‘{print $(NF-2)}’|cut -d. -f1)”
if test $L05 -gt 5
then
mail -s “$SUBJECT $L05″ “$EMAIL” < $TEMPFILE
mail -s “$SUBJECT $L05″ “$EMAIL1″ < $TEMPFILE
fi
rm -f $TEMPFILE
———————————–
Change permission
3 . chmod +x /root/loadalert
4. Add cron
# vi /var/spool/cron/root
* * * * * /root/loadalert >/dev/null 2>&1
5. Restart Cron
# /etc/init.d/crond restart
6. Check cron log for error mesage…
# tail -f /var/log/cron
Recent Comments