Re: Learning Scripting
There is another way to exclude the unwanted 'grep' in the ps listing.
Use a regular expression that matches what you're looking for but that
can't match itself. A simple example, where I'm just looking for a
command name, say 'ssh-agent':
ps ax | grep '[s]sh-agent'
grep parses the pattern and looks for 'ssh-agent', which can't match the
pattern, so you eliminate the 'grep' from the output. And only need to
run grep once.
Anil Gupte wrote:
Beautiful! We were just talking about this and someone mentioned grep
now I know how to use it too.
----- Original Message ----- From: "Michael Marsh"
Sent: Tuesday, May 16, 2006 5:21 PM
Subject: Re: Learning Scripting
On 5/16/06, Anil Gupte <firstname.lastname@example.org> wrote:
The idea was the system cannot start the X-Server sometimes when the
off unexpectedly. So, if an error message is found the system should be
shutdown nicely and then when it reboots, it runs an fsck and cleans up.
The second set of checks is because sometimes the grep command itself
the ps ax, and we do not want to reboot for this spurious occurrence.
It looks like your script might generate false negatives, if the error
condition is there but grep shows up in ps. You might want to instead
check1=$(ps ax | grep -i "$msg1" | grep -v grep)
check2=$(ps ax | grep -i "$msg2" | grep -v grep)
You then shouldn't need check10 and check20. Another option would be
to test check10 and check20 against check1 and check2. I think the
above is probably better, though.