Check if program is running
Hi!
I'm just starting to look into shell scripts. I would like to know if there is a CLI way of checking whether or not a program is running (something along the lines of 'thisCommand -kaffeine' returning a boolean value)? |
Hi,
I cannot remember a more elegant way (sure some guru around here can provide us with a fascinating solution); but this does the trick: Code:
some_variable=`ps -C kaffeine|grep -v PID` It could be that there is an option in "ps" doing exactly what you look for; do "man ps" and have fun reading it. Regards edit: or more transparent: substitute "grep -v PID" by "grep kaffeine" |
I'm not particularly knowledgable on the matter - only started looking into it a few days ago - but aren't you supposed to 'enclose' the ps pipe grep command into a variable on its own?
Like Code:
a=$(ps -C | grep kaffeine) |
both of those examples are called command subtitution. Either one can be used. you can either put the command in backticks
Code:
`enter command here` Code:
$(enter command here) |
OK - so I've got that little part working - and I've discovered the wonderful 'if grep' construct :) Just one more question:
How would I go about picking up exit values (0 or 1) and variables from other scripts? |
the special variable $? gives the return value of the last command executed
Code:
cat filename | grep hhh I have not used bash for a while, I think that is the correct syntax |
There isn't any way getting the return value of one specific script?
|
lets say you have a script called script.sh
Code:
script.sh Is that what you are asking? |
I suppose I was thinking java style (thisFile.myVar) - but it isn't important, as I can easily accomplish what I want using this more sequential approach.
|
All times are GMT -5. The time now is 08:36 AM. |