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

  • K.I.S.S. - works great - I love it - rep given. – darkAsPitch Feb 24 '10 at 17:34

/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:

update-rc.d --defaults <yourscript>

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):

ln -s /etc/init.d/<myscript> /etc/rc2.d/S50<myscript>

As calling shutdown when shutting down (level 0), going single user (level 1) or rebooting (level 6) is probably not that wise an idea.

  • Thanks Frenchie, I wish I could give you both right answer marks! That was incredibly detailed and I have learnt a lot. charlesbridge addressed it much more simply however, and for that, he gets the check. – darkAsPitch Feb 24 '10 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.