Script to generate interface configs on Linux

Wednesday, September 16th, 2009

Generate ifcfg-eth1 307-366 configs.

touch ifcfg-eth1:{307..366}
for f in ifcfg-eth1:{307..366}; do cat origfile > “$f”; done
for f in eth1:{307..366}; do echo “DEVICE=$f” >> “ifcfg-$f”; done
for f in {307..366}; do echo “IPADDR=aaa.bbb.ccc.$((f-239))” >> “ifcfg-eth1:$f”; done

origfile contains:

GATEWAY=eee.fff.ggg.hhh
TYPE=Ethernet
BOOTPROTO=none
NETMASK=255.255.255.192

Sending image emails with mutt from command line

Friday, July 10th, 2009

ls | perl -ne ‘$a=$_;chomp $a;$b=”mutt -s \”poza $a\” -a $a <email> < message.txt\n”;print $b;`$b`’

Script to autorestart httpd server if it fails

Thursday, June 18th, 2009

I use this script on a cpanel server..if output of pgrep command is 0 then the $restart command is issued

#!/bin/bash
restart=”/scripts/restartsrv_httpd”
pgrep httpd || $restart
exit 0

If its a VPS then I might add to clear the Semaphore Arrays.

for i in `ipcs -s | grep nobody | awk ‘{print $2}’`; do ipcrm -s $i; done

Then I put this script into Cron to run every 5 minutes.

# MIN HOUR DAYOFMONTH MONTH DAYOFWEEK COMMAND
*/5 * * * * /root/checkhttp.sh