How can I check for a string match AND an empty file in the same if/then bash script statement?
Posted
by
Mike B
on Server Fault
See other posts from Server Fault
or by Mike B
Published on 2012-10-14T05:33:33Z
Indexed on
2012/10/14
9:40 UTC
Read the original article
Hit count: 185
I'm writing a simple bash script to do the following:
1) Check two files (foo1 and foo2).
2) If foo1 is different from foo2 and foo1 NOT blank, send an email.
3) If foo1 is the same as foo2... or foo1 is blank... do nothing.
The blank condition is what's confusing me. Here's what I've got to start with:
diff --brief <(sort ./foo1) <(sort ./foo2) >/dev/null
comp_value=$?
if [ $comp_value -ne 0 ]
then
mail -s "Alert" [email protected] <./alertfoo
fi
Obviously this doesn't check for blank contents. Any thoughts on how to do that?
© Server Fault or respective owner