Shell Script to check a file

I'm required to write a simple shell script that when it runs it writes the output which is a simple barcode to a tmp flat file which I can do the bit I'm struggling with...

The next time it runs I need to check the tmp output file to see if that barcode is in the output file and if it is send out an email alert
Any help gratefully received

Hi Worky,

What have you tried?

When you say "barcode" what exactly do you mean? If you want ti check the file exists then it's likely to be asimple shell test - checking the contents will be a bit more involved.

Regards

Gull04

Its just an 8 char barcode in a file XA123456 in a txt file

All I want to do is check if it already exists in that file and if it does sned out an email

--- Post updated at 10:24 AM ---

The file is called failed_list
and is a flat txt file containing barcode

X1234567
X2345678
X3456789

The next time the job runs and creates failed list if there is a re occurance of a barcode I want it to mail me using mailx

Hi,

Here is a code snippet, from a shell script you should be able to modify to suit quite easilly. But as you haven't shown me what you've tried or your code I can't be more precise.

### Adjust this for your environment
MAILLIST="<enter your mail address here multiple address saparated with comma(,)>"

EXIST=`grep ${BARCODE} ${TEMPFILE}`
if [ $EXIST = 0 ]
then
    echo "The Barcode ${BARCODE} already exists." >/tmp/outmail
    cat /tmp/outmail|mailx -s "Barcode Already Exists" $MAILLIST
else
    echo "New Barcode ${BARCODE} created." >/tmp/outmail
    cat /tmp/outmail|mailx -s "New Barcode Created." $MAILLIST
fi

Regards

Gull04

Thanks
This was what I had

cat failed_list | xargs -I{} grep -w {} failed_list_check > failed_alert


fail_check=`cat failed_alert | wc -l`
if [ $fail_check != 0 ]
then

echo 'cat failed_alert'
mailx -s

Do I get you right that the new bar code string is in a file called failed_list_check and should be tested for existence in a "history" file failed_list , and, if found, send a mail? If so, try

grep -qffailed_list_check failed_list && mailx -s"something" "$MAILTO" < failed_list_check