shell script to shutdown computer
I would like to have my home server shutdown every day at a certain time. Today I log into it and issue the shutdown command, but I would like this to be done automatically.
My thought was to write a simple shellscript (shutdown -h 22:30) and have cron run it. The problem is that only root can initiate shutdown. Can I solve with with a script, and what needs to be done, or is there a better way of accomplishing this? Thanks! |
Why a script to issue a system command? I've never tried shutdown, but can't think of a reason the following wouldn't work. Just add this line to root's crontab.
Code:
30 22 * * * root /sbin/shutdown -h |
Quote:
if you add the line: Code:
twallstrom ALL=NOPASSWD: /bin/cat |
The cron solution seems the best to me. I shut down all workstations in my home every night using that line.
However, I think Weibullguy made a mistake. The line he gave is to be entered in /etc/crontab. When it is in the root's crontab the user name should not be specified. Entering this line in /etc/crontab is the preferred way, because it is readable by all so you can see what happens even when you are an ordinary user. Don't forget to put an additional blank line in crontab after the last line otherwise it won't work. jlinkels |
All times are GMT -5. The time now is 02:48 PM. |