Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to run a 4 commands before a hibernate and another 2 commands after update. Is it also possible to arrange the time/squence of each commands,if yes then could you explain how?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

You can run commands before and after hibernation or suspension (note there is a difference; hibernation is to disk, suspension is to memory) by creating a script in /etc/pm/sleep.d:

#!/bin/bash

case "$1" in
  hibernate)
    # put commands to run on hibernation here
    ;;
  thaw)
    # put commands to run when returning from hibernation here
    ;;
  suspend)
    # put commands to run on suspend here
    ;;
  resume) 
    # put commands to run when returning from suspension
    ;;
esac

The filename of the script will dictate the order in which the scripts run compared to other scripts in sleep.d. Within your script, your commands will run in whatever order you put then in the script.

share|improve this answer
    
I've got to try that later –  user128712 Jun 15 '13 at 2:11
    
Could you explain why the filename has to be 'xxname' where x is a number, what does x mean? –  user128712 Jun 15 '13 at 4:45
    
The files are ordered (and therefore executed) in alpha-numeric order. The number is not necessary, but it provides a way of controlling the order of the scripts. –  David Edwards Jun 15 '13 at 9:11
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.