Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP grep issue

Status
Not open for further replies.

dsm666

IS-IT--Management
Mar 9, 2004
40
US
I copied the information from this thread to reconstruct my ftp script; however I am not getting any emails when the 550 error occurs. I checked sendmail and it's working fine:
ftplog=$HOME/log/preprocess.$$

ftp -nv $FTP_HOST<<END_SCRIPT>>$ftplog
quote USER $FTP_USER
quote PASS $FTP_PASSWD
lcd $TEMPDIR
cd $REMOTE_DIR
binary
rename $BNAME $newfname
get $newfname
dir
sleep 5
delete $newfname
quit
END_SCRIPT

xfrcnt1=`grep "^550 " $ftplog | wc -l`
xfrcnt2=`grep "^5[0-9][0-9] " $ftplog | wc -l`

if [[ $xfrcnt1 -ne 0 ]];then
echo "ftp 550 error $MBOX $BNAME" | mailx -s "ftp 550 error $MBOX $BNAME" myemailaddress
elif [[ $xfrcnt2 -ne 0 ]];then
echo "ftp 5xx error $MBOX $BNAME" | mailx -s "ftp 5xx error $MBOX $BNAME" myemailaddress
else
echo "success"
fi

If someone could take a look, i'd really appreciate it, thanks
 
Do you get any output if you run grep "^5[0-9][0-9] " manually against the FTP log?

Incidentally, you can use grep -c string filename instead of grep string filename | wc -l.

Annihilannic.
 
This is what I get when I ran that:
grep "^5[0-9][0-9]" log/preprocess.29314
550 pgi_pm.UPD: Cannot create a file when that file already exists.
550 pgi_pm.UPD: The system cannot find the file specified.
 
also here is the output from the log file:
+ + wc -l
+ grep ^550 /ceunix_test/ceunix/log/preprocess.29314
xfrcnt1= 2
+ + wc -l
+ grep ^5[0-9][0-9] /ceunix_test/ceunix/log/preprocess.29314
xfrcnt2= 2
+ [[ 2 -ne 0 ]]
+ mailx -s ftp 550 error H478BBBX pgi_pm.pcs myemailaddress
+ echo ftp 550 error H478BBBX pgi_pm.pcs
+ mailx -s ftp 550 error H478BBBX pgi_pm.pcs myemailaddress
+ echo ftp 550 error H478BBBX pgi_pm.pcs
 
Try something along the lines of
Code:
if grep -q ^500 $ftplog
then
 echo "ftp 550 error $MBOX $BNAME" | mailx -s "ftp 550 error $MBOX $BNAME" myemailaddress
elif grep -q ^5[0-9][0-9] $ftplog
  echo "ftp 5xx error $MBOX $BNAME" | mailx -s "ftp 5xx error $MBOX $BNAME" myemailaddress
else
  echo success
fi

On the internet no one knows you're a dog

Columb Healy
 
Strange enough you log file says that mailx has been launched 2 times ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi Columb
this is what I see when adding your code:
+ grep -q ^500 /ceunix_test/ceunix/log/preprocess.log
grep: illegal option -- q
Usage: grep -hblcnsviw pattern file . . .
+ grep -q ^5[0-9][0-9] /ceunix_test/ceunix/log/preprocess.log
grep: illegal option -- q
Usage: grep -hblcnsviw pattern file . . .


 
Hmm... no -q option on grep? You'll need to redirect your output to /dev/null so
Code:
if grep ^500 $ftplog >/dev/null
then
 echo "ftp 550 error $MBOX $BNAME" | mailx -s "ftp 550 error $MBOX $BNAME" myemailaddress
elif grep ^5[0-9][0-9] $ftplog > /dev/null
  echo "ftp 5xx error $MBOX $BNAME" | mailx -s "ftp 5xx error $MBOX $BNAME" myemailaddress
else
  echo success
fi


On the internet no one knows you're a dog

Columb Healy
 
I am so sorry to drag this on like this, but I was able to find all the emails in my junk mail. thanks to all for your input. It's much appreciated. God Bless!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top