Guest User

Locky: locks all active X sessions with a screensaver

a guest
Mar 14th, 2011
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.06 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # locky: lock ALL screens at suspend or hibernate with xscreensaver
  4.  
  5. IS_ACTIVE="$( \ps u -C xscreensaver | awk '{print $1}'|grep -v USER )"
  6. DISPLAYS_TO_CHECK="$( \ps u -C X | tail -n +2  | awk '{print $12}')"
  7. # check if xscreensaver is running. if not, just skip on.
  8. if [ -z "$IS_ACTIVE" ]
  9. then :
  10.     echo "Cannot lock screen. Going to sleep anyway..."
  11. else
  12.     echo "Locking the screen before sleeping."
  13.         # run the lock command as the user who owns xscreensaver process,
  14.         # and not as root, which won't work.
  15.         # Feed correct display variable for user!
  16.         echo "$IS_ACTIVE"|while read line;
  17.         do
  18.         user="$(getent passwd $line |awk -F : '{print $1}')"
  19.             echo "$DISPLAYS_TO_CHECK"|tr " " "\n"|while read displays;
  20.             do
  21.                 if dpyinfo=$(su - $user -c "xdpyinfo -display ${displays}.0 2>&1 1>/dev/null"); then
  22.                     echo "$user : DISPLAY=$displays /usr/bin/xscreensaver-command -lock $dpyinfo"
  23.                     break;
  24.                     su - $user -c "DISPLAY=$displays /usr/bin/xscreensaver-command -lock" &
  25.                 else
  26.                     echo "$dpyinfo"
  27.                 continue;
  28.                 fi
  29.             done
  30.         done
  31. fi
Advertisement
Add Comment
Please, Sign In to add comment