How can I hibernate/suspend from the command line and do so at a specific time

You can use the at command to schedule any action, including running the commands detailed in that question.

For example, if you want to hibernate in 30 minutes:

echo 'pmi action hibernate' | at now + 30 min

Or if you want to suspend at 11:00 pm:

echo 'pmi action suspend' | at 11pm

If you need to run a command as root, run at with sudo rather than the command itself with sudo (since sudo should only be run interactively, unless you've configured it not to ask for your password). For example, the equivalents of the above commands using pm-hibernate and pm-suspend are:

echo pm-hibernate | sudo at now + 30 min

echo pm-suspend | sudo at 11pm


For relative specification (e.g. "after 30 minutes") you can simply use sleep command to make suspending/hibernating command wait.


Examples:

Wait 30 minutes, then suspend:

sudo sleep 30m; sudo pm-suspend

Wait 1 hour, then hibernate:

sudo sleep 1h; sudo pm-hibernate

For specific times repeated - like shutting down computers are a specific time each day. use cron.

crontab -e

add the following:

15 14 1 * * pmi action suspend

If you want to customize it.

* * * * * command to be executed
- - - - -
| | | | |
| | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
| | | ------- Month (1 - 12)
| | --------- Day of month (1 - 31)
| ----------- Hour (0 - 23)
------------- Minute (0 - 59)

For a one time job us the at command

For example, if you want to hibernate in 30 minutes:

echo 'pmi action hibernate' | at now + 30 min

Or if you want to suspend at 11:00 pm:

echo 'pmi action suspend' | at 11pm