I recently found and tweaked a script that is supposed to help my 12.04, heavily modified system, maintain its wifi connection to my home router. The connection's been kinda dodgy, and I decided polling for a new dhcp lease regularly might help that.
The script I found and modified looks like this:
Code:
#!/bin/bash
if ! `ping -c 1 -w 1 -q 192.168.1.1 </dev/null &>/dev/null` ; then
echo "resetting eth0 $(date)" >>/home/user/renew-eth0.txt
ifdown eth0
ifup eth0
else
echo "eth0 operational $(date)" >>/home/user/renew-eth0.txt
fi
exit 0
What the script does, of course, is run a ping test and, based on the result of the ping test, either brings down, then up again, eth0, and sends a message to a log file to that effect, or simply writes to a file with a time/date stamp that eth0 is already up. Pretty simple.
Now, when I bring eth0 down manually, then run that script manually (sudo) from the command line, it works fine: eth0 gets an IP. When I specify the path to that file as a cron job for the root user, however, it doesn't run as expected. It does do the ping test and write the time/date stamped message to the specified file if eth0 is operational. If the ping test is unsuccessful, it also writes the time/date stamped message to the log file: but it does not succeed in bringing up eth0: the computer gets no IP when the script runs this way, despite the fact that it
does get an IP when I run the script manually from the command line.
So, what could be going on here? Why would the script run successfully when entered at the command line, but only run partially when specified as a cron job? I'm confused by this. Anyone else not?
Thanks,
James
Bookmarks