I have a process that fails regularly & sometimes starts duplicate instances..
When I run:
ps x |grep -v grep |grep -c "processname"
I will get:
2
This is normal as the process runs with a recovery process..
If I get
0
I will want to start the process
if I get:
4
I will want to stop & restart the process
What I need is a way of taking the result of ps x |grep -v grep |grep -c "processname"
Then setup a simple 3 option function
ps x |grep -v grep |grep -c "processname"
if answer = 0 (start process & write NOK & Time to log /var/processlog/check)
if answer = 2 (Do nothing & write OK & time to log /var/processlog/check)
if answer = 4 (stot & restart the process & write NOK & Time to log /var/processlog/check)
The process is stopped with
killall -9 process
The process is started with
process -b -c /usr/local/etc
My main problem is finding a way to act on the result of ps x |grep -v grep |grep -c "processname".
Ideally, I would like to make the result of that grep a variable within the script with something like this:
process=$(ps x |grep -v grep |grep -c "processname")
If possible.
pgrepif you have that.) – Mat Nov 23 '13 at 13:15grepcan be influenced even by unprivileged users. You should have a look atmonitdor at least list onlyroots processes (or the daemon user) – hek2mgl Nov 23 '13 at 13:17ps aux | grep "[p]rocess" but the result was more complicated thanps x |grep -v grep |grep -c "process"` so I am not too sure how to interpret the printout & use it in my script.. In what scenario could the original grep be fragile? I will be the only user ever logged into this server.. Also, how would I incorporate "list only roots processes (or the daemon user)" in the grep?? Thankyou for your time – linuxnoob Nov 23 '13 at 13:36