Click to See Complete Forum and Search --> : Shell conditionals question


mc-fine
09-06-2001, 01:49 PM
Hey guys I need a little help in writing some code for a shell script.

I am trying to read what is written in a text file, compare it to the result I want and if they dont match carry out a statement.
So far my code looks like this:

if (`head cron/result.txt` != "OK.")
then mail -s "PING Result: `date`"< cron/result.txt mc-fine@balh.com
fi

Unfortunately there is a problem with my condition. The error I get is:

bash: OK.: command not found

Anyone know how I can read the cron/result.txt and check if it reads "OK."?
I also tried (`head cron/result.txt` != `echo OK.`).

TheLinuxDuck
09-06-2001, 02:30 PM
#!/bin/bash
#
echo "Trying file"
#
RESULT=`head -n 1 result.txt`
if [ "$RESULT" = "OK." ]; then
echo "first line of result.txt matched"
else
echo "file did not match"
fi


Try that. (^= The [] brackets indicate that a test is being done.

mc-fine
09-06-2001, 03:31 PM
Mr. Duck. Would you do me the honor of allowing me to be the mother of your children? :p

Thanks a lot. I had been scratching my head about that for a few days.

TheLinuxDuck
09-06-2001, 03:44 PM
Originally posted by mc-fine:
<STRONG>Mr. Duck. Would you do me the honor of allowing me to be the mother of your children? :p</STRONG>

(^=

<STRONG>Thanks a lot. I had been scratching my head about that for a few days.</STRONG>

Notaprob. You were right there, anyway, but just needed a push in the right direction. Shell scripting is nice for many things, thats for sure.

If you're interested in some great resources for scripting, let me know, I've got a few laying around somewhere..