[GTALUG] Locking KDE 5 screen from shell script

Mauro Souza thoriumbr at gmail.com
Wed Aug 12 11:35:13 UTC 2015


You could change this line
ps aux | grep cinnamon-session | grep -v grep

to this
pgrep cinnamon-session

It's cleaner and works well.

To answer the main question, try to install bashdb and run the script thru
it. It's the bash debugger, it's far more powerful than bash -vx.
On Aug 12, 2015 04:22, "Randy Jonasz" <rjonasz at rjonasz.org> wrote:

> I recently installed kde5 on debian stretch.  I have a yubikey which I use
> to log in with.  I'd like to lock the screen when I remove the yubikey.  I
> have it working with cinnamon and lxde but I can't quite get it with kde.
> I can lock the screen if I run the shell script from a terminal as root but
> when I remove the yubikey the shell script returns error code 1.
>
> Here's my shell scripts:
>
> ykgone.sh
>
> #! /bin/sh
> if [ -z "$(lsusb | grep Yubikey)" ] ; then
>        if [ ! -z "$(ps aux | grep cinnamon-session | grep -v grep)" ] ;
> then
>                /bin/su rjonasz -c "DISPLAY=:0 cinnamon-screensaver-command
> -l"
>        elif [ ! -z "$(ps aux | grep startkde | grep -v grep)" ] ; then
>                /usr/bin/sudo -u rjonasz -H -i  /usr/local/bin/lockkde.sh
>        else
>                /bin/su rjonasz -c "DISPLAY=:0 xscreensaver-command --lock"
>        fi
> fi
>
>
> lockkde.sh
>
> #! /bin/sh
>
> kde_pid=`pidof kdeinit5`
> export `cat /proc/$kde_pid/environ|grep -ao
> 'DBUS_SESSION_BUS_ADDRESS=[[:graph:]]*'`
> /usr/bin/qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock
>
>
> I can't seem to figure this one out.
>
> Thanks for any help!
>
> Randy
>
> --
> Even philosophers will praise war as ennobling mankind, forgetting
> the Greek who said: 'War is bad in that it begets more evil than
> it kills.'
>
> Immanuel Kant
>
>
> ---
> Talk Mailing List
> talk at gtalug.org
> http://gtalug.org/mailman/listinfo/talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gtalug.org/pipermail/talk/attachments/20150812/af90a793/attachment.html>


More information about the talk mailing list