2

In X I've used the following script (from here) to lock the computer with i3lock each time pm-suspend or pm-hibernate are invoked.

/etc/pm/sleep.d/00screensaver-lock:

#!/bin/sh
 # 00screensaver-lock: lock workstation on hibernate or suspend

 username=andreas
 userhome=/home/$username
 export XAUTHORITY="$userhome/.Xauthority"
 export DISPLAY=":0"

  case "$1" in
    hibernate|suspend)
       su $username -c "/usr/bin/i3lock & 
       ;;
    thaw|resume)
       ;;
    *) exit $NA
       ;;
  esac

Now I'm in the process of setting up a console-only laptop (a minimal Debian install without the X server installed.)

I've tried using the above script on that machine to lock my session using vlock. (That is: I've switched out i3lock with vlock in the version of the script I'm using on the console machine.) I've also tried commenting out the two lines starting with export XAUTHORITY and export DISPLAY=":0" as they are X specific.

The script doesn't work on the no-X machine.

How should I call vlock each time the computer suspends/hibernates?

  • There are several scripts on that page you refer to, help us out by telling us what you have done (which script), paste it into your question, which you can edit, and explain what you mean by console-only since this sort of implies not using X a gui. – X Tian Mar 6 '14 at 10:56
2

This simple script does the trick:

#!/bin/sh

case "$1" in
    hibernate|suspend)
       /usr/bin/vlock -ans &
       ;;
    thaw|resume)
       ;;
    *) exit $NA
       ;;
esac
  • Thank you for this, very useful. You can also export USER to have vlock ask for a user password instead of root's: USER=me /usr/bin/vlock -ans & – GnP Oct 24 '14 at 17:44

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.