![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| output of command rup | kiranrasane | UNIX for Advanced & Expert Users | 1 | 03-27-2008 07:31 AM |
| ls command output | arsheshadri | AIX | 1 | 08-20-2007 03:23 AM |
| Output of ps -ef command | dbrundrett | UNIX for Advanced & Expert Users | 6 | 01-06-2005 11:48 AM |
| Output of ps command | ls1429 | UNIX for Dummies Questions & Answers | 1 | 02-03-2003 07:40 AM |
| Output command | berty007 | Shell Programming and Scripting | 4 | 11-29-2002 02:27 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
if command not having the right output
Code:
if cat /var/log/messages | grep fail = " " then echo "Good" else echo "Bad" fi |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
You need backquotes to capture output
Then double quotes to make it a single argument for test And you need test And it should be a truely empty string Code:
if test "`cat /var/log/messages | grep fail`" = "" then echo "Good" else echo "Bad" fi Code:
if test -z "`cat /var/log/messages | grep fail`" ... Code:
if grep fail /var/log/messages
then
echo failed
else
echo no problems
fi
|
|
#3
|
|||
|
|||
|
#!/bin/sh
LOG_FILE=log.txt grep -l fail /var/log/messages* > $LOG_FILE if [$? -eq 0] then echo "Bad" echo "Files that contains failures are" cat $LOG_FILE else echo "Good" fi exit |
|
#4
|
|||
|
|||
|
thank you all for the prompt reply ! All of the info provided is very useful to me thanks !
|
|
#5
|
|||
|
|||
|
Code:
#!/bin/sh
LOG_FILE=log.txt
grep -l fail /var/log/messages* > $LOG_FILE
if [$? -eq 0]
then
echo "Bad"
echo "Files that contains failures are"
cat $LOG_FILE
else
echo "Good"
fi
exit
$? ==> unknown variable or all variable ? -eq ==> equals ? |
|
#6
|
|||
|
|||
|
Code:
awk '/[Ff]ail/{filename[FILENAME];nextfile}END{for (i in filename) print i }' /var/log/messages*
|
|
#7
|
|||
|
|||
|
filthymonk i am just checking the status of the execution of the grep command so i have used ($? variable) and checking for 0
|
|||
| Google The UNIX and Linux Forums |