1752802 Members
5809 Online
108789 Solutions
New Discussion юеВ

Re: Script HELP

 
SOLVED
Go to solution
Isaac_4
Frequent Advisor

Script HELP

I need script that send email when my ftpscript fail for some reason Now every thing work fine.
My Script search error from logs:
---------------------------------
#Move last LOG to OLD
mv /tmp/logschk.txt /tmp/logschk.txt.OLD
>/tmp/logschk.txt # Touch file LOG
-------------------------------------
#LOG env arch.
export LOG=/tmp/logschk.txt
-----------------------------
# env for my parent error search criterial (no such file etc...)

export ERRORES=/tmp/chkctrl.txt
------------------------------------------
# Find error w/match parten file and create result in LOG file
grep -f $ERRORES /tmp/ftp* 0>>$LOG
--------------------------------------
#Send email w/attach (logschk.txt attach name) with match errors to alias user call " test"

uuencode $LOG logschk.txt |mailx -s 'Falla FtpServicio' test

I made the above script to find and send some error ocurred if match with a parent file that I need verify. if this no match happen the script send a empty email.

I need send email only when some grep match with parent file other ways nothing happend.

rigth now all way send email but i need send when only have match with my parten file

Pls, a little help with my limited

Thsk every one.



The time is gold
2 REPLIES 2
James R. Ferguson
Acclaimed Contributor

Re: Script HELP

Hi:

One way is to test your '$LOG' file for a non-zero size:

if [ -s ${LOG} ]; then
uuencode ...
fi

...This test returns true only if the file exists and has a size greater than zero.

Regards!

...JRF...
Arturo Galbiati
Esteemed Contributor
Solution

Re: Script HELP

Hi,
you could:
------------------------------------------
# Find error w/match parten file and create result in LOG file
N_ERRORES=$(grep -c $ERRORES /tmp/ftp*)
if [[ $N_ERRORES > 0 ]]; then
grep -f $ERRORES /tmp/ftp* 0>>$LOG
#Send email w/attach (logschk.txt attach name) with match errors to alias user call " test"

uuencode $LOG logschk.txt |mailx -s 'Falla ($N_ERRORES) FtpServicio' test

fi

in this way you will have the number of the error in the subject of the mail as well.


HTH,
Art