You are not logged in.
Pages: 1
I write a bash script for toggle conky
#!/bin/bash
if ! pgrep conky >/dev/null; then
echo "Turning conky ON"
conky &
else
echo "Turning conky OFF"
pkill conky
fi
exit 0If I name this script conky_toggle.sh and run then "pgrep conky" will always return 0 like conky already run.
How to write this kind of scripts correct? What can replace pgrep and pkill?
Last edited by Kirill Bugaev (2018-09-06 02:09:14)
Offline
pgerp -x, pkill -x.
Or write C daemon program which will save process id of runned conky and toggle.
Offline
Instead of pgrep, use pidof with a full path:
pidof /usr/bin/conkyAre you familiar with our Forum Rules, and How To Ask Questions The Smart Way?
BlueHackers // fscanary // resticctl
Offline
Or busybox's version doesn't need a full path but matches the full name:
/usr/lib/initcpio/busybox pidof conkyThis is particularly useful for python programs (e.g., qutebrowser) as coreutils' pidof will not match their names or full path at all.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thanks a lot. Will use busybox version.
Last edited by Kirill Bugaev (2018-09-06 04:49:06)
Offline
Pages: 1