cron job not running
Hi everyone,
I want my computer to shut itself down at 1am everyday. So what I did was type "su -c 'crontab -e'" and added in the line: Code:
0 1 * * * init 0 I tried different things like adding quotation marks to "init 0", putting the full path ("/sbin/init 0"), and using an alternative command ("shutdown -h now"), but to no avail. What am I doing wrong? Thanks, Vince |
Try creating a log file to test:
0 1 * * * init 0 2>&1 > /tmp/shutdown.log Do you get anything in the log when it is supposed to run? |
No, apparently it doesn't even run because when I type "cat /tmp/shutdown.log", the file hasn't even been created.
|
Have you tried
/sbin/halt or /sbin/poweroff Instead of init 0 |
If that doesn't work it would be interesting to see if your cron jobs are even being run - try this one for example:
0 1 * * * date 2>&1 > /tmp/cron-test.log Do you see the correct date and time in the log file? ie - 1:30 |
You might try creating an empty log file first. Sometomes it will not create the file for you. Try this and see if it works.
Code:
touch /tmp/cron-test.log > /dev/null |
So I added the line "29 23 * * * date 2>&1 > /tmp/shutdown.log" to my crontab file, restarted crond, and made sure that I typed "touch shutdown.log" before 23:29. But yet nothing shows up in /tmp/shutdown.log.
Any more ideas? Thanks, Vince P.S. Hurray, my 400th post! |
What procedure did you use to add it to your crontab file?
|
su
crontab -e <edit> crontab -l (to verify) /etc/init.d/crond restart |
bump
|
Hey just a simple test to verify whether your crond is runninig
do <code>#su - #touch /root/cron_test #crontab -e and add the following job : 0,5,10,15,20,25,30,35,40,45,50,55 * * * * date >> /root/cron_test</code> After saving the file just verify crontab -l and also there is no need restart crond it will rebuilt its files again. This is only a test script and will put the output of date command in /root/cron_test after 5 mins every hour. Remember to remove it once you have tested it. .... Nitin Batta .... http://nitinb.blogspot.com __________________ If this helped you, please take the time to rate the value of this post by clicking the affero button |
Not sure if this is it, but make sure that the init file is in the path that cron is using to run. It does not run with the full path that your user account runs as. It also runs as the user for which the cron job was created - you will likely have to be root to run this cron job as it is written.
Put the full path to init - probably /sbin/init or /usr/sbin/init - It is common that the path that cron uses is very minimal unless you specify path as a variable in cron: PATH = /usr/sbin:/sbin:/bin:/usr/bin.....etc... |
Quote:
Quote:
Quote:
There's no other way to schedule a shutdown? |
Shutdown has execute permissions generally for only for the root.
Quote:
So you will set the shutdown as a cronjob for root. When you set a cronjob as any user you need not be logged in as that user for the job to run .... so its to set shutdown as a cronjob for root. #which shutdown /usr/bin/shutdown (Dummy O/p) so u'r crontab would be #crontab -e 0 1 * * * /usr/bin/shutdown -h now |
That's what I did originally but it didn't work.
I made sure that I su'ed before typing crontab -e. But nothing seems to happen unless I'm logged in as root. |
All times are GMT -5. The time now is 07:42 PM. |