Skip to content

Instantly share code, notes, and snippets.

@ju916
Created April 29, 2019 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ju916/e85629890d50b4e31f64f3620e930b45 to your computer and use it in GitHub Desktop.
Save ju916/e85629890d50b4e31f64f3620e930b45 to your computer and use it in GitHub Desktop.
Script to lock XScreensaver
#!/bin/sh
# echo "USB device removed `date` $@" >>/tmp/xscreenlock.log
#user=ju
user=`who | grep ':0' | awk '{print $1}'| head -1`
if [ ! -z "$user" ] ; then
DISPLAY=:0 sudo -n -H -u "$user" /usr/bin/xscreensaver-command -lock >> /tmp/xscreenlock.log 2>>/tmp/xscreenlock.log
fi
@borg1622
Copy link

In Zeile 6 ist noch ein Fehler enthalten.
Das Kommando who gibt bei mir z.B. folgenden Ausgabe:

tollerAdmin      tty7         2021-01-29 12:00 (:1) 
tollerUser       tty8         2021-01-29 12:11 (:0)

grep ':0' matcht auf beide Zeilen. Und head -1 wählt dann den Nutzer tollerAdmin, obwohl dieser auf Display :1 arbeitet.

Daher einfach Zeile wie folgt ändern:
user=`who | grep '(:0)' | awk '{print $1}'| head -1`

Viele Grüße :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment