Hi..everyone,
Here is the crontab entry
Quote:
#crontab -l
# m h dom mon dow command
*/2 * * * * /home/linux/net_restart
|
Here is the net_restart script content
Quote:
cat net_restart
#!/bin/bash
now=`ifconfig eth0 | grep -i "inet addr" | awk '{ print $2}' | cut -d. -f 4`
ip=198
rm -rf /tmp/test
if [ $ip -ne $now ]; then
/etc/init.d/networking restart > /dev/null
fi
|
This is because, in one of the server the IP address is often changing itself to dhcp even the static IP address is given in /etc/network/interface file. Then I'll login to the server and running "
/etc/init.d/networking restart" command to bring the IP address back to 198. But we cannot say that when it changes to dhcp, sometimes working fine for a week and sometimes for 2 or 3 days and sometimes it is changing to dhcp twice in a day. So I thought of make a shell script and add it to crontab for watch in every 2 minutes.
First I thought of to check this from my PC and then add it to the server if everything goes fine. The script file works fine if I manually run and it is changing back to static IP address if the last octet of IP address is not "198", but it is not through crontab. Then I created /tmp/test file and added an entry in script to remove the file. But it is neither removing /tmp/test file nor restarting networking service through crontab but both can be done only if I run it manually. I also removed all crontab entries and re-added only this script but still cronjob is not working.
So please help me why crontab is not working in my PC. I am using ubuntu 11.04