script again
Hi all,
Just want to ask what is wrong with the script below, so I just want to know if "TIMEOUT" word is present on pogi.log, if the keyword exist then it will print "NOT OK" if not it will print "OK" #!/bin/bash log_file='/tmp/pogi.log' if [ ! grep -i "TIMEOUT" $log_file ]; then echo "OK" else echo "NOT OK!" fi I tried to manipulate the log file by removing the "TIMEOUT" keyword but it still gives me this result: ./timeout.sh: line 3: [: too many arguments NOT OK! thanks in advance and happy 4rth of July |
You should call grep not [ (aka test):
Code:
#!/bin/bash |
Quote:
when the script detected "TIMEOUT" on the log, the "TIMEOUT" keywords from the pogi.log appears on the screen along with the echoed "NOT OK!" [pogi@test tmp]$ ./ntubski.sh app1.ear deployment in progress .............................. [FAIL (TIMEOUT)] app2.ear deployment in progress .............................. [FAIL (TIMEOUT)] app3.war deployment in progress .............................. [FAIL (TIMEOUT)] NOT OK! when script did not detected the keyword "TIMEOUT" (outcome is fine as expected) [pogi@test tmp]$ ./ntubski.sh OK |
pass option -q to grep to suppress output.
Code:
#!/bin/bash |
...bit shorter and if the log file is kinda long you can bailout after one "TIMEOUT" ("-m1"):
Code:
LOGFILE="/tmp/pogi.log"; grep -Fqi -m1 "TIMEOUT" "${LOGFILE}" && RES="OK"; echo "${RES:="NOT OK"}" |
Quote:
Quote:
|
Quote:
by adding on the test commands below. #!/bin/bash log_file='/tmp/pogi.log' if [ -e ! /tmp/pg_pid.txt ] && [ -e ! /tmp/jboss7_pid.txt ] && [ ! -f $JBOSS_DEPLOY_LOCATION/*.failed ]; then echo "OK" else echo "NOT OK!" fi |
Quote:
Code:
#!/bin/bash Code:
#!/bin/bash |
Quote:
Hi ntubski, I'm trying to find a way on what is the better approach on this: grep the server.log file and check if 'deployment failed' exists would this be okay to add in the above condition? [ ! grep -i 'deployment failed' server.log ] so if the check finds a 'deployment failed' it would report not okay |
Code:
grep -iq "deployment failed" serverlog || echo "true" && echo "false" |
Quote:
|
All times are GMT -5. The time now is 02:20 AM. |