Script Help - If Statement
Hi guys i need some help.
Im trying to run a command then grep a log file to see if the command was successful or not. In the log file there are specific words i can grep for to check for success or failure. Then weather it fails or succeeds i will send a mail to myself. heres what i have; Code:
#!/bin/bash Then if statement is were im falling short, and i think im putting the back ticks in the wrong place as well. Please help me |
quote your multitoken strings and you should be fine.
e.g. if [[ "$CHECKB" == "open for e-bus" ]] instead of if [[ "$CHECKB" == open for e-bus ]] |
Thanks the if statement doesnt through an error anymore more but the statement is not working as expected.
The statement will only switch to the "else" therefore the variable "CHECKA" and "CHECKB" are failing. Ive been starring at this for an hour and i know its something simple but cant put my finger on it :( |
The line CHECKA='grep' "Server server1 stopped" SystemOut.log tells bash to set variable CHECKA to grep, to run the command "Server server1 stopped" SystemOut.log and then to unset CHECKA. It should have produced an error message as this experiment at the command prompt shows
Code:
c@CW8:~$ CHECKA='grep' "Server server1 stopped" SystemOut.log Code:
CHECKA=$( grep "Server server1 stopped" SystemOut.log 2>&1 ) Code:
echo "DEBUG: CHECKA: '$CHECKA'" |
Most commands set the exit status, zero indicates success and non-zero indicates failure (different number for each possible type of error). In shell scripts $? is the exit status of the last command.
So if your scripts follow this convention (i.e. using exit 0 when everything is OK and exit 1 , exit 2, etc) you can test exit status after the command like: Code:
$STOPSRV If your scripts don't set exit status correctly, grep does so you can do something like the following Code:
$STOPSRV |
Many Thanks, guys you provided the solution
|
Please mark as SOLVED once you have your solution.
|
All times are GMT -5. The time now is 06:50 PM. |