Operating System - HP-UX
1833016 Members
3285 Online
110048 Solutions
New Discussion

Script to check the process

 
Son dam bi
Advisor

Script to check the process

I have a script ( /tmp/my_script ) to check the process ,

$/tmp/my_script
report1 ok
report2 ok
report3 ok

my reqiurement is :
if run myscript , the result generated three lines ( as above ) , then it is normal , if the result is not three lines , then it is not normal , I want to send a notify mail to me in case it is not normal , the logic is as below .

====================
/tmp/my_script
if result is three lines ; then do nothing
else
send notify mail to me
fi
=====================

can advise how can I write this script ? thx
5 REPLIES 5
Suraj K Sankari
Honored Contributor

Re: Script to check the process

Hi,
tell me one thing if your script fail then how many lines are display.

Suraj
Son dam bi
Advisor

Re: Script to check the process

thx reply ,

not regular , may be one , two or over three lines or even a empty result , so what I want is if the result is not three lines , then define it is a fail case , then send notify mail .

thx for help .
F Verschuren
Esteemed Contributor

Re: Script to check the process

A small sh script can do this:


sh /tmp/my_script |grep -v "report1 ok" |grep -v "report2 ok"|grep -v "report3 ok" > /dev/null
if $?=0
then
echo mail
else
echo "no mail"
fi
Hakki Aydin Ucar
Honored Contributor

Re: Script to check the process

You can write like this code:
#!/usr/bin/sh

if (( `cat myscript|wc -l` != 3 ))
then
mailx ..
else
echo good
fi
Arturo Galbiati
Esteemed Contributor

Re: Script to check the process

Hello,
you could use this way:
create a new script:
#/usr/bin/sh
cd /tmp
my_script 2>my_script.err 1> my_script.log
cat my_script.log
if [[ $(wc -l my_script.log != 3 ]] || [[ $(wc -l my_script.err > 0 ]]; then
(echo; uuencode my_script.err my_script_err.txt; echo;uuencode my_script.log my_script_log.txt) \
mailx -m -s "my_script KO" your@address
fi
#eof

HTH,
Art