Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
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
Then I restarted crond by typing "/etc/init.d/crond restart". To test it, I reset my clock to 12:55am and rebooted. But when the hour rolled over, nothing happened.
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.
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
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.
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:
Originally posted by nitin_batta 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.
Looks like cron works here. But I can't figure out why it won't load "init 0"
Quote:
Originally posted by sjspig 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
Answer:
Quote:
Originally posted by vincebs 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.
So I have to be root in order for the cron job to run? I don't feel comfortable leaving my Internet-connected computer running as root all the time...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.