Link to home
Start Free TrialLog in
Avatar of addady
addady

asked on

bash shell "if not"

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
Avatar of ahoffmann
ahoffmann
Flag of Germany image

if [ ! grep ... ]; then

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

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial