Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Simple question: what params can be used to shutdown a computer running Linux/OSX in 30 seconds? I've always run Windows, where I would go shutdown -s -t 30 but the parameters are different. I've looked it up here but it will only let you shut a computer down at a specific time (like 8:00) rather than in a specific amount of seconds.

share|improve this question
add comment

migrated from stackoverflow.com May 12 '11 at 22:56

This question came from our site for professional and enthusiast programmers.

3 Answers

up vote 4 down vote accepted

In OS X you can shutdown in one minute using the following command:

sudo shutdown -h +1

AFAIK, it's not possible to specify seconds instead of minutes with this command.

You can also reboot by using -r instead of -h.


EDIT:

As you mentioned in your comment, you can add a delay programmatically, then shut down the system immediately with

shutdown -h now

But note that that command will require root access.

share|improve this answer
    
meh. So no using decimals. I suppose that's alright, I was wondering because I'm trying to work on a cross-platform Java application that can shutdown a computer. So I could just make it sleep for 30 seconds before shutting down immediately. But would sudo shutdown -h shutdown the computer without an intentional delay? –  icnhzabot May 12 '11 at 22:55
    
@icnhzabot sudo shutdown -h now would shut the computer down immediately with no warning. –  Austin May 12 '11 at 23:07
    
ok thanks. so for root access I should do sudo shutdown -h now right? –  icnhzabot May 12 '11 at 23:29
    
@icnhzabot That won't work for an automated script/program because it prompts the user for their administrator password at the command line. You'd have to run your script as root and just call shutdown -h now. If you need help with that, you should make a new question (assuming you can't find the answer elsewhere). Also, don't forget to mark the best answer here as "accepted" if it answered your question. –  Austin May 12 '11 at 23:43
add comment

Using the basic calls, I don't see a way to do it with seconds, but it looks like you can do it with minutes:

time Time is the time at which shutdown will bring the system down and
     may be the word now (indicating an immediate shutdown) or specify
     a future time in one of two formats: +number, or yymmddhhmm,
     where the year, month, and day may be defaulted to the current
     system values.  The first form brings the system down in number
     minutes and the second at the absolute time specified.

In other words:

shutdown -h +1

If you want to shut it down in 1 minute.

share|improve this answer
    
do you know if it would work with .5? –  icnhzabot May 12 '11 at 22:53
    
There's an error here -- the -r option is for reboot, not shutdown. You have to use -h for shutdown. –  Austin May 12 '11 at 22:54
    
@Austin ugh, fixed that inline. –  onteria_ May 12 '11 at 22:56
add comment

As pointed out, the command

sudo shutdown -h +1

Adds one minute.

If you wanted to do it in seconds or hours or something very specific you could do something like:

shutdown -h `date --date "now + 60 seconds"`

EDIT: The above no longer works on more recent builds of Ubuntu. Thanks for pointing that out @zitrax. My mistake you're right.

But you can still do it but it seems maybe to the nearest minute.

sudo shutdown -h `date --date "now + 10 minutes" "+%H:%M"`

Which is somewhat pointless when the +m parameter is easier to type.... ahhh oh well.

share|improve this answer
    
Does not work (at least on linux), this gives the time in another format than expected. –  Zitrax Feb 21 at 12:30
    
@Zitrax, just because it didn't work in your case doesn't mean it doesn't work in all flavours of Linux. I'd like you to also note the backtick ` is different to a single quote '. I'm guessing this is why it didn't work for you. This absolutely works in all versions of Ubuntu since at least 10.04. And as Ubuntu is based on Debian it'll work on that too. It might be more constructive to say "Does not work on ...." rather down down vote and make a blanket statement. Linux is a generic term, it's not a version. But I actually think you typed it wrong. Try again. –  Matt H Feb 22 at 13:18
    
I tried again on my home machine and it's not working there either. I know how backticks works. So I have tried on Ubuntu 13.10 and Kubuntu 13.10. Could be that I using a different locale ? Output from date --date "now + 60 seconds" for me is lör 22 feb 2014 21:25:03 CET and if I use that together with shutdown it prints "invalid timevalue" (translated to English). So your statement that the version you wrote absolutely work in all versions of ubuntu is simply wrong. If I specify the format to date it works though, like this: date --date "now +60 seconds" +%H:%M. –  Zitrax Feb 22 at 20:32
    
Tried switching to english locale, but it didn't work either. So I am not sure why it works for you. –  Zitrax Feb 22 at 20:37
    
Must be your version of the shutdown command. Looks like the version that comes with Ubuntu may be different. It's authored by Scott Remnant from Conanical. It must be that it accepts a wider range of date input values. Works for me and at least 3 others who upvoted. –  Matt H Feb 23 at 22:22
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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