You are not logged in.
Pages: 1
Hi everyone,
I want to create a shell script in order to toggle eclimd on/off use that in my conkybar.
My pseudo code looks like this:
Check if eclimd is running.
If false: start eclimd echo ON to conky.
else stop eclimd echo OFF to conky
So far my code is:
#!/bin/sh
SERVICE='/usr/share/eclipse/eclimd' #make it easy to reuse this and the next step could be to grep the filename part after toggle e.g toggleEclimd.sh and the service would be eclimd
fuser $SERVICE > /dev/null 2>&1
if [ $? -eq 0 ]; then
$SERVICE
else
sudo killall $SERVICE # Here I would like to actually grep the PID and just kill PID. because killall just terminate the program and not the same as CTRL + c (in xmonad mod+shift+c)
This doesnt work. If I switch the starting and the killing. Then it works, but this doesnt make much sense to me. Isnt it checing to see fuser finds a running program and returns true if it does?
If I make the starting and killing echo ON or OFF, how is this displayed to conky? Because in my head ${exec toggleEclimd.sh} will execute it again and again? or? :S
Offline
If you just want conky to display if your program is running, put
${if_running eclimd}Eclimd ON${else}Eclimd OFF
somewhere in the TEXT section of your .conkyrc
Then use your script to toggle eclimd.
In your script, it would probably be better to use 'pidof' or 'pgrep' to determine if eclimd
is running instead of 'fuser'.
if pid=$(pgrep $SERVICE); then
kill -SIGINT $pid
else
$SERVICE
fi
Edit: To answer your question.
If a command works in bash, it returns 0.
So in your script, if the 'fuser $SERVICE' is successful, it returns 0 into $?.
Last edited by rockin turtle (2012-10-24 03:12:01)
Offline
Oh I new the conky problem was easy. Should have read the man page better. But thanks.
I can see that the update you provide to my script is better, but it doesnt kill it. If I type kill pid(the actual pid) its killed the way it should.
Offline
I probably got that wrong. Perhaps it should instead be:
kill -SIGTERM $pid
I never remember which signal corresponds to C-c. Anyway, I hope you get everything working as you like.
Offline
Pages: 1