I'm aware I can use (sudo?) shutdown -h hh:mm in a terminal window to shut down a system, however the user that is logged in is a kiosk user, which is locked down in such a way that terminal (or any window other than firefox, for that matter) cannot be opened.
My question is:
Is there a way I can do this without having a terminal window opened? I've read about cron, but can't quite work it out.
How can I change the shutoff time depending on what day it is?
3 Answers
Cron will work very well for this.
You need first to find the complete path to the shutdown command:
a@ubuntu:~$ which shutdown
/usr/sbin/shutdownKnowing the path to the shutdown command, you can add the below line (with tweaks) to the end of /etc/crontab:
30 23 * * * root /usr/sbin/shutdown -h nowAt 23:30 (11:30 PM), the kiosk will shut down. No matter what user is logged in, the shutdown command runs as root.
(If you don't want to use the global crontab, log in as root and use crontab -e. Use the same above syntax without the root).
Cron Format:
MM HH DD OO WW commandMM: Minute, 0-59HH: 24-hour hourDD: Day of monthOO: MonthWW: Day of Week (Sunday is 0, Monday is 1)command: Self-explanatory
A cronjob seems to be the best way because you can specify different times for different days. On Gnome based systems you can just install GNOME Shedule Tasks by using
sudo apt-get install gnome-scheduleand then configure the cronjob using the GUI.
otherwise you would have to use sudo crontab -e and then add the following lines
30 11 * * 1-5 /sbin/shutdown -h now
30 10 * * 0,6 /sbin/shutdown -h nowthis would shutdown the PC at 11:30 from Monday to Friday and on 10:30 on Saturday and Sunday. The structure is very simple:
minute (0-59), hour (0-23, 0 = midnight), day (1-31), month (1-12), weekday (0-6, 0 = Sunday), command For more information about this you could also just check out CronHowto
2We can shutdown automatically at specified time by simply running command sudo poweroff in crontab.
If you want to shutdown the system at 6:30 pm everyday. Type in terminal:
sudo crontab -eedit
30 18 * * * poweroff 3