bash shell  "if not"

addady
addady used Ask the Experts™
on
How can I change this if:

if grep "Slave_Running: Yes" /home/status.txt > /dev/null; then
   echo Mailing show slave status error report!!!
   /home/mysql-mail-problem.sh
fi


to "if not"

Thanks
Addady
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
if [ ! grep ... ]; then

(you need to check first which exist status of grep you're interested in)

Author

Commented:
grep exit status should be is 0 if selected lines are found and 1 otherwise.  in my case when the line "Slave_Running: Yes" not appent in the file I want to enter to the if.

> if [ ! grep ... ]; then
I add it and it fail on error

# if grep "Slave_Running: Yes" /home/status.txt > /dev/null; then
if [ ! grep "Slave_Running: Yes" /home/status.txt > /dev/null ]; then
  echo Mailing show slave status error report!!!
  /home/mysql-mail-problem.sh
fi


./tmp.sh
./tmp.sh: [: Slave_Running: Yes: binary operator expected
oops, was too lazy ..

grep "Slave_Running: Yes" /home/status.txt > /dev/null
if [ $? -ne 0 ]; then
     echo Mailing show slave status error report!!!
fi

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial