The original command that you've shown us that you're using to see if master was running is:
So, if master is running, you get a count of 1 for the process you're looking for, an additional 1 because bash is running ./test2.sh master, and a third 1 because you're running bash -x ./test2.sh master.
Sometimes it is easier to debug things like this by changing:
to:
and examine the contents of the files step1, step2, and step3 to see what processes were matched that you hadn't expected.
As RudiC suggested, using ps -ax -ocomm gets rid of the problem here. But adding tees in a pipeline frequently helps when shortcuts like -o comm don't apply.
These 3 Users Gave Thanks to Don Cragun For This Post:
The same idea but implemented with two grep's
Note that [ $TMP ] is not robust in case $TMP contains shell-special characters or test-operators like -n or =
So should be quoted and prefixed with a -n operator. [[ $TMP ]] might be safe as well.
if pgrep isn't what you want, could you make an expression from the item you are searching for? I avoid using a contruct like ps -ef | grep this | grep -v grep byt writing it as ps -ef | grep -E "thi[s]" so the expression does not match its own process. If you are passing it a loop of items to check, it could get a bit fiddly, but with variable substitution you could achieve it, perhaps like this:-
You still might have to be careful because there is a risk that there are false positives, e.g. someone stops a service called MAINPROC (so there are no process like that running, but then edits the file /var/log/MAINPROC, and the editor command shows up as a process matching your search and therefore you think it is still running.
Can you tell us more about the processes you are looking for and therefore might be a better way to be checking for them. Perhaps if they write their process-id in a file in /var/run/name then you can read that file and make sure the process is what it should be.
It depends how far you want to push this. You processes might respond to a signal to say that they are running okay, for instance and you could actually give them a nudge to make sure that they are happy and not stuck in a loop, for instance or they could frequently be re-writing a file with the current date (best as date +%s format) and if it is out of date by too long (you decide what is too long and compare to current date +%s value) then raise an alert.
Hello -
I am running a script that is outputting to a log. Let call it output.log
I would like to monitor that log until the line "Build Successful" is found.
I think I would need to use the grep command.
How would I do that in a loop?
Thanks
Marty (1 Reply)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
I need to search through the users home directories for keywords, display them. The code listed below will show... (7 Replies)
Hello everybody,
I have been searching it, but it seems I am unable to find the correct information, that s why I am asking you guys, hoping somebody get an idea.
Here is my problem :
I want a script to loop until a string is identified in a log file.
Here is the script :
#!/bin/sh... (5 Replies)
So this is what I'm trying to do:
I have a file called registry.txt which has a list of registry entries I want to search for.
I have another file called inctrl.txt on which I want to perform the search on.
Here's the example contents of registry.txt
SOFTWARE\Microsoft\Security... (3 Replies)
:wall:
I have a requirement to search a log file that never rotates for certain values. If I find them I pipe them to a another file. To log file is constanyl being appened with new lines and never rotating Easy so far.
The problem is I dont want to pipe out matches already seen before. ... (3 Replies)
Hi all,
I have the below script to get input but i cannot get grep to work.
input1.txt
AAAAAAAAG
input2.txt
>gi|184009.1| LEAFY-like |AAAAAAAAGSGGGDHLPY
However, when i use grep -f input1.txt input2.txt
i cannot get any output matches (note that the match is underlined).
Is it... (8 Replies)
Hello All,
I have been reading posts on here for a while, but this is my first post. I have a document in which many sentences appear, and I am piping it through an exterior script which will tag each word in the document with its part of speech (not part of my script, just background). The... (3 Replies)
Hi All,
Reference to my previous post
I need to compare all the lines in the file1 with file2
for this condition if file1 {$3,$5} ==file2 {$3,$5} then grep file2{$1}latest date.
need output in file3
10/04/2008
09/04/2008
09/04/2008
08/04/2008
can anyone suggest me
Thanks... (0 Replies)
Hi ,
I am trying a script which takes user input userid . I am stuck how to check whether that is a valid user id or not in the audit log files. My code is :
cd $CCP_AUDIT
cat * > /export/home/$USR/l***/files
echo "UserId:\c"
read UserId
#Date Function
echo "DATE : \c"
read xxx
I... (7 Replies)