Click to See Complete Forum and Search --> : crontab help


perfectly_dark
09-26-2003, 05:47 PM
I wrote a neat script that can save the current IP address into a file. The script just calls ifconfig, grepps the output, cuts it up untill it gets the IP address under the PPP0 interface and saves it into a file, ip.address. This all works fine and dandy from the console, but I need it to run every few minutes, so I setup a crontab. However, now whenever crontab runs the script ip.address is empty. Anyone know why that is and have a posible solution?

mdwatts
09-26-2003, 06:55 PM
It might help if you posted the crontab entry you added for the script so we can have a look.

perfectly_dark
09-26-2003, 07:47 PM
whoops...my bad
Here's what a crontab -l when logged in as root gets me for the script in question:
10 * * * * /etc/rc.d/rc.ipscript

Thx

X_console
09-27-2003, 09:11 AM
what does your script look like? I do something similar to what you're doing and it works fine for me.

mdwatts
09-27-2003, 09:24 AM
Originally posted by perfectly_dark
whoops...my bad
Here's what a crontab -l when logged in as root gets me for the script in question:
10 * * * * /etc/rc.d/rc.ipscript

Thx

Try something like

10 * * * * root cd /etc/rc.d; ./rc.ipscript

You will need to restart the cron daemon though some distros (mine do) detect the changes to /etc/crontab and automatically restart cron.

If necessary

/etc/init.d/cron restart

or

/etc/rc.d/init.d/cron restart

depending on where the cron startup script resides.

perfectly_dark
09-30-2003, 04:32 PM
Sorry for the long reply, Here's the script, it's still not working:

ifconfig | grep --max-count=1 'inet' | cut -d: -f2 | cut -dB -f1 > ip.address

mdwatts
10-01-2003, 04:42 PM
Originally posted by perfectly_dark
Sorry for the long reply, Here's the script, it's still not working:

ifconfig | grep --max-count=1 'inet' | cut -d: -f2 | cut -dB -f1 > ip.address

You didn't say whether you tried what I suggested in my previous post. Did it not work?

Are those scripts set as executable and in your PATH (echo $PATH)?

perfectly_dark
10-02-2003, 08:16 PM
No, I changed the crontab and restarted it as you suggested but it didn't work. The script is executable but it isn't in my PATH, how do I add it?

perfectly_dark
10-09-2003, 05:43 PM
Ok, looks like no one knows what my problem is...does any one know another way to get the IP address every few minutes and save it into a file using something other than ifconfig?

shakin
10-10-2003, 10:09 AM
Put your script in a more appropriate place, like /usr/local/bin and make it executable by everyone. My guess is that cron is getting permission denied when trying to execute it.

mdwatts
10-10-2003, 04:40 PM
Originally posted by perfectly_dark
No, I changed the crontab and restarted it as you suggested but it didn't work. The script is executable but it isn't in my PATH, how do I add it?

Ok, looks like no one knows what my problem is...does any one know another way to get the IP address every few minutes and save it into a file using something other than ifconfig?


But I did post an example on what to add to cron if the script is not in your PATH.

10 * * * * root cd /etc/rc.d; ./rc.ipscript

So that will

cd to whatever directory (/etc/rc.d in this example)

and then the ./ preceeding the script name tells the shell to look in that directory for the script.

10 * * * * root cd /path/to/script ; ./<name of script>

perfectly_dark
10-10-2003, 11:43 PM
Oh, I get it! Well, I tried it but it didn't work. I did however manage to solve the problem. I don't know what's wrong with using the crontab command, but I put the scheduled scripts into the file /etc/crontab and they work just fine. Thanks for all the help