Hi guys, how are you today?
I'm having trouble trying to make a script. What I want to do is check if xScreenSaver is running in my user account. If not, run it. If it's running, kill it. So this is the script I've made:
Code:
#!/bin/bash
if [ -n $(pgrep -u $(whoami) xscreensaver) ]
then
kill $(pgrep -u $(whoami) xscreensaver) &
echo "XScreenSaver: Off"
else
xscreensaver -no-splash &
echo "XScreenSaver: On"
fi
The problem is that I've echoed the output of
$(pgrep -u $(whoami) xscreensaver) and it always seems to add 4 numbers to the pid, even if the pid doesn't exist. What do I mean by "doesn't exist"? That no xscreensaver is running in my user, and if I run pgrep -u $(whoami) xscreensaver in bash, I get not output, but if I run the command though the script, I get (for instance) 4050. If I run it again, I get 4054, and again 4058... etc. What the hell is going on with that?
Thanks in advance for your answers.
Cheers.