![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| output of command rup | kiranrasane | UNIX for Advanced & Expert Users | 1 | 03-27-2008 10:31 AM |
| ls command output | arsheshadri | AIX | 1 | 08-20-2007 07:23 AM |
| Output of ps -ef command | dbrundrett | UNIX for Advanced & Expert Users | 6 | 01-06-2005 02:48 PM |
| Output of ps command | ls1429 | UNIX for Dummies Questions & Answers | 1 | 02-03-2003 10:40 AM |
| Output command | berty007 | Shell Programming and Scripting | 4 | 11-29-2002 05:27 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
if command not having the right output
Code:
if cat /var/log/messages | grep fail = " " then echo "Good" else echo "Bad" fi i have 10 files named messages.0 , messages.1 , .... till 9 then i need cat all the files and grep to see if there is anything failing. therefore, i used the above command however, it doesn't seems to be working please help. |
|
||||
|
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 alternatively use Code:
if test -z "`cat /var/log/messages | grep fail`" ... But you could get rid of all the above with Code:
if grep fail /var/log/messages
then
echo failed
else
echo no problems
fi
|
|
||||
|
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
[$? -eq 0] $? ==> unknown variable or all variable ? -eq ==> equals ? |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|