LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   problems using cron (https://www.linuxquestions.org/questions/linux-software-2/problems-using-cron-150737/)

Mugatu 02-26-2004 09:37 AM

problems using cron
 
i have some unresolved network problems:

http://www.linuxquestions.org/questi...hreadid=145436

where my network stalls out and the only way to fix it is to restart my nic. so i created a script in my /root directory called netrestart which contains:

Code:

ifconfig eth0 down
ifconfig eth0 up
dhcpcd

and then i ran crontab -e and added this line:

Code:

0 0,6,12,18 * * * /bin/bash /root/netrestart 1> /dev/null
i made the netrestart script executable, and if i type ./netrestart it seems to work fine, but my cron job isn't executing. what did i skrew up? do i need to add #!/bin/bash or whatever to the top of my script? i figured i didn't cause it works fine when i run it. what about the fact that i ran crontab as root? i can't run this script as a user cause i won't be able to run ifconfig. root doesn't need to be logged in for root's cron jobs to run does it?

jailbait 02-26-2004 10:58 AM

"0 0,6,12,18 * * * /bin/bash /root/netrestart 1> /dev/null"

I think that you have specified to run your command on every December 6 when December 6 happens to be the eighteenth day of the week. The fields are:
minute hour day month dayofweek command

Here is a crontab man page:
http://campuscgi.princeton.edu/man?crontab

___________________________________
Be prepared. Create a LifeBoat CD.
http://users.rcn.com/srstites/LifeBo...home.page.html

Steve Stites

Mugatu 02-26-2004 11:21 AM

Quote:

Originally posted by jailbait
"0 0,6,12,18 * * * /bin/bash /root/netrestart 1> /dev/null"

I think that you have specified to run your command on every December 6 when December 6 happens to be the eighteenth day of the week. The fields are:
minute hour day month dayofweek command

if the first argument stands for minutes, then this should run at the beginning of the specified hours. if the second argument represents hours, then should this not run at 12am, 6am, 12pm, and 6pm? and then it should run every day, every month, every day of the week. i'm still learning and as always i'm open to suggestions, but honestly i'm not sure what i skrewed up. maybe i'm just misunderstanding it entirely...

jailbait 02-26-2004 02:15 PM

" should this not run at 12am, 6am, 12pm, and 6pm? and then it should run every day, every month, every day of the week."

Yes. You are correct. I gave you an incorrect answer off the top of my head where I assumed that the commas would be treated as white spaces. Sorry. Now I have checked your cron entry against a reference book, "Running Linux". Everything checks out OK.

In my crontab (set up by Fedora) there is a SHELL=/bin/bash variable set at the beginning and my crontab entries do not have a shell specified. So maybe you are specifying /bin/bash twice. You could try:
0 0,6,12,18 * * * /root/netrestart 1> /dev/null

It is also possible that Mandrake is using a variation of the cron system called the Vixie cron system. Fedora and Red Hat use the Vixie variation of cron and Mandrake patterns itself after Red Hat. You can tell that you are using Vixie if you have a script installed called /usr/bin/run-parts. If so, then your crontab entry should be:
0 0,6,12,18 * * * root run-parts /root/netrestart 1> /dev/null

___________________________________
Be prepared. Create a LifeBoat CD.
http://users.rcn.com/srstites/LifeBo...home.page.html

Steve Stites


All times are GMT -5. The time now is 06:20 AM.