script works ok manually, but not in cron
Hello,
I'm having a lot of problems with my internet provider. It seems that I get the IP from their dhcp, but when it runs out, I don't get a single that I my server should request a new one. So in that situation I have a IP on my eth1, but internet doesn't work. I looked online and found a little script that checks if internet works (google) and if it doesn't it releases ip from eth1 and ask for a new one. The strange thing is that although the script gets called every 15 minutes (root user) it dons not do the job. If I call it manually, it works immediately and every time. Here it is: #!/bin/bash WGET="/usr/bin/wget" $WGET -q --tries=10 --timeout=5 http://www.google.com -O /tmp/index.google &> /dev/null if [ ! -s /tmp/index.google ];then echo "Internet connectionm down...geting new ip for eth1" dhclient -r eth1 sleep 5 dhclient eth1 touch /home/yoda/dhcp-new else echo "Internet connection ok" fi I really don't know what to do and why this is happening. Any ideas? I'm running latest ubuntu server. Thanks! |
You probably have to specify the full path to the dhclient command.
|
How does your cron entry looks like?
Code:
crontab -l | grep scriptname Code:
/pathblahblah/scriptname > logfile |
Thanks a lot for the answers!
crontab -l | grep check-internet returns this: 0,15,30,45 * * * * /etc/init.d/check-internet #check internet, get new ip from b-net on eth1 if internet is down 1,16,31,46 * * * * /etc/init.d/check-internet I added the second line recently trying to get it to work Since my net connection is now ok, the log from the script just says the echo line: "Internet connection ok" I'll try the full path to the dhclient, but why is it that it works great when I start the script manually? Thanks!! |
It's actually hard to test it out since I need to be in a situation when the internet stops working and it seems it's happening in random intervals. :(
I already e-mailed my provider and they said they were doing a lot of upgrading in my are and that it will be fixed. And it did get better for a period of time, but it didn't last. |
keep in mind that cron runs in its own environment and does not inherit any PATH of the user it is called under.
also please use code flags, select advance to help you, when posting code. makes like much simpler to read... now i cant say for Ubuntu, but it should be the same. my dhclient resides in /sbin: Code:
[user@centos Season_1]$ which dhclient Code:
/sbin/dhclient eth1 Code:
LOG=/path/to/log.log |
Hi!
Well, I added the full path to the dhclient and it seems to work now! Thanks a lot! I'll see what will be happening in next few days. I added a simple lines that do a log of sorts like this: Code:
touch /home/some-user-folder/dhcp-released I'll report back when I see how it's working now... |
All times are GMT -5. The time now is 10:47 PM. |