How would one automatically shutdown an ubuntu OS 30 minutes after it was turned on? Or 15 minutes after it was turned on? Etc?
I tried creating an init.d script like so:
shutdown -h +5
But my box does not shut down after 5 minutes.
How would one automatically shutdown an ubuntu OS 30 minutes after it was turned on? Or 15 minutes after it was turned on? Etc?
I tried creating an init.d script like so:
shutdown -h +5
But my box does not shut down after 5 minutes.
You could use cron and the @reboot flag to schedule the shutdown if you add this to the root crontab:
@reboot shutdown -h +30
/etc/init.d contains the launch scripts, but doesn't actually tell each runlevel what it should do. The actual scripts are called as symlinks from /etc/rc[0-6].d where [0-6] is the runlevel you're entering.
More specifically, the symlinks are given the name:
[SK]nnScript where [SK] is Start or Kill, nn is the order (lower first) and Script is the name of the file in /etc/init.d. Scripts scheduled to start are called with --start and those to be stopped --stop as switches.
On debian/ubuntu you can populate those scripts with:
so that the appropriate symlinks get created in /etc/rc[0-6].d/
I'd strongly recommend though that you just symlink it yourself into runlevel 2 (default):
As calling shutdown when shutting down (level 0), going single user (level 1) or rebooting (level 6) is probably not that wise an idea.