cancel
Showing results for 
Search instead for 
Did you mean: 

Check string

 
SOLVED
Go to solution
Son dam bi
Advisor

Check string

In my system , there is a program will generate a log to the text file , this program will run times per day , can advise if I want to check the text file , if the text file have a string "Uuable to run program" , then send mail to me , can advise what can i do ? thx
4 REPLIES
Horia Chirculescu
Honored Contributor
Solution

Re: Check string

Hello,

The following script should help:

#-------------------------------------
#Change those to suit your needs:
user_mail=your_email_address_here
logfile=your_logfile_name_here

found=`grep -c "Unable to run program" $logfile`

if [ "${found}" != 0 ]; then
echo "Some program was unable to run"
mail -s "Some program was unable to run" $user_mail << EOF
Hello,
Some program (or programs) was (were) unable to run. The number of programs with some problems is: $found.

Please check the file $logfile
EOF
fi
#-------------------------------------

Best regards from Romania,
Horia Chirculescu
Best regards from Romania,
Horia.
Suraj K Sankari
Honored Contributor

Re: Check string

Hi,
run this command or put into a file and run through crontab.

#grep "Unable to run program" path_of _your_logfile |mail -s "Uuable to run program" your@mailid.com

In this case your log file should new everytime when you apply this command.

Suraj
Torsten.
Acclaimed Contributor

Re: Check string

I would check if your program delivers some return values - this might be easy to handle.

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Tingli
Esteemed Contributor

Re: Check string

Where does the "Uuable to run program" come from. Why not let the original script to send the mail?