Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am using Fedora 13 and for shutting down and rebooting automatically, we have the following commands:

# shutdown -h/-r now 

Similarly, if I want to make my system go into suspend mode after sometime, what command should I use?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

The unix philosophy is to have tools that perform one job, plus the shell to combine them. So we'll combine a suspend command with a do-something-later command. I don't know what the standard command for suspending is on Fedora (there are several floating around); I'll use pm-suspend which is the usual command on Ubuntu.

To suspend after X seconds: sleep X && pm-suspend

To suspend at a given time: echo pm-suspend | at HH:MM

share|improve this answer
1  
Nice answer. It really is more fruitful to also make this a small lesson in the unix philosophy. +1 –  Steven D Sep 7 '10 at 21:52
add comment

The pm-suspend utility (which is contained in the pm-utils package and likely already installed on your machine) is what is used to send your computer into suspend mode. Thus to suspend "right now," you can run (as root or using sudo):

# pm-suspend

Unfortunately, pm-suspend does not take a time parameter as far as I know. However, you could write a wrapper script that took a time parameter. Save the script somewhere in your $PATH and chmod +x it. Do not call it "suspend". A simple one may look like this:

#!/bin/sh
#change this following line to wherever pm-suspend lives
suspend="/usr/sbin/pm-suspend"

#make sure we are root
if [ "$(id -u)" != "0" ]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi

if [ -z "$1" ]; then
    echo "mysuspend: time in seconds expected"
    exit 1;
elif [ "$1" = "now" ]; then
    echo "Suspending now!"
    wait="0"
else
    #make sure we get a number.
    echo "$1" | grep [a-zA-Z] > /dev/null
    if [ $? -ne 0 ]; then
        echo "Suspending in $1 seconds"
        wait="$1"
    else
        echo "mysuspend: time in seconds expected"
        exit 1
    fi
fi

sleep "$wait"
$suspend

Warning: I have not tested this beyond "works for me".

You may consider changing the suspend command to pm-suspend-hybrid which will also save a hibernation file in case you run out of power while suspended.

Other utilities that you may be interested in or that could make your script more robust are pm-hibernate, pm-is-supported.

share|improve this answer
add comment

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.