How to deliver an error message from script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to deliver an error message from script?
# 8  
Old 09-23-2014
Hi what is output of below code
Code:
 ftp_log=`/usr/bin/ftp -nv $HOST <<EOF
user $USER $PASSWD
#cd Ordens
binary
mget *HLR*
bye
EOF`
 
echo $ftp_log

# 9  
Old 09-23-2014
The exit status you will get from ftp will always be 0 because the command worked...
# 10  
Old 09-23-2014
Some versions of ftp will return a zero return code if the ftp command itself succeeded, rather that what you are really interested in which is if the action you asked ftp to perform succeeded. I do this by capturing all the output to a log file and then searching for the success flag. The message numbers are three digits. Those 400-999 are errors, so I run a double grep against the log file:-
  • Firstly to find any lines starting with that range of numbers
  • Secondly to ignore any lines that have the string bytes sent or bytes received just in case a file is an awkward number of bytes that is picked up by the first search.
It's roughly built on:-
Code:
grep -E "[4-9][0-9][0-9] " ftp.log | grep -Ev "bytes sent|bytes received"

We do look for more things, so I'm actually using files in both grep commands, but they are specific to our needs.


I hope that this helps.

Robin
# 11  
Old 09-23-2014
Hi

After modifying
Code:
ftp_log=`/usr/bin/ftp -nv $HOST <<EOF`
user $USER $PASSWD
#cd Ordens
binary
mget *HLR*
bye
EOF
echo $ftp_log

I got the following output:

Code:
 ./get_HLR.sh
Connected to 10.100.48.47.
220-FileZilla Server version 0.9.39 beta
220-written by Tim Kosse (Tim.Kosse@gmx.de)
220 Please visit http://sourceforge.net/projects/filezilla/
Remote system type is UNIX.
331 Password required for hlr_dump
230 Logged on
?Invalid command
200 Type set to I
mget HLR01_21092014? 200 Port command successful
150 Opening data channel for file transfer.
226 Transfer OK
local: HLR01_21092014 remote: HLR01_21092014
905052160 bytes received in 34 seconds (26232.79 Kbytes/s)
221 Goodbye
root@moneta #

This time was successfully because, we free up some space on the destination file system
# 12  
Old 09-23-2014
Excellent. Now you have known good output to work with. You can see from your original post that the error is highlighted by this message:-
Code:
426 Connection closed; transfer aborted.

Have a go at trying to manage that and then see if you can replicate it and capture the failure.

Let us know how you get on (with code and output/errors)



Regards,
Robin
# 13  
Old 09-23-2014
Now you can use that log msg to achive your task like below
Code:
ftp_log=`/usr/bin/ftp -nv $HOST <<EOF`
user $USER $PASSWD
#cd Ordens
binary
mget *HLR*
bye
EOF`
if [ `grep "No space left on device" $ftp_log | wc -l` -gt 0 ];
then
    echo "No space left on device" | mailx -s "Error:No Space" youremail@yourcomp.com
else
    echo "File transfered SUCCESSFULLY at $(date)."
fi

# 14  
Old 09-23-2014
You might have to code many many exceptions trying to guess all the possible phrases to worry about this way. It would also mean that you are firing up grep and wc as new processes for every possibility you can think of, and how can you be sure you have thought of them all.

The documentation tells us that the error codes are 400-999, so I would refer you to my earlier suggestion.

If you feel that you don't like this, then I would strongly recommend searching for success messages and report anything else as a failure. Over time, you may hit some false errors, but you can then allow for them. If you miss a failure then that can have more serious consequences.


I've learned by painful experience that having too many false errors is far better than missing a real failure.


Regards,
Robin




As a final note, grep has a -c flag to could records, so saving wc being needed at all, so it will run much faster.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script error message

I have this UNIX script code with a query to export sql table in Oracle and export to csv file. The code gets the data correctly. However, when I run the script second time, I got the error message "not spooling currently" and shows the older data in csv file. When I delete the csv file and run... (5 Replies)
Discussion started by: Hope
5 Replies

2. UNIX for Beginners Questions & Answers

UNIX script error message

Greeting!! I wrote the below script to e-mail me only file names in a specific directory when a file is delayed for some time in a that directory. I am getting unexpected eof error message. I don't want any email if the folder is blank.(if the condition is not met) I am not getting the email at... (4 Replies)
Discussion started by: Hope
4 Replies

3. Shell Programming and Scripting

Passing error message back to script

I have one script that calls another script during execution. The other script does some processing, then either returns with exit 0 (if successful), or exits with error code numbers (if failed). However, in addition to the error code, I would like for that second script to be able to pass a... (4 Replies)
Discussion started by: AcerAspirant
4 Replies

4. Shell Programming and Scripting

Script returning an error message on exiting

Hi, I am writing a script in which I am using an IF-Else statement. Code sample: # Check for the product. If (test "$3" = "Pet") Then Product_Code="PI" elif (test "$3" = "Breakdown") Then Product_Code="RI" elif (test "$3" = "Travel") Then Product_Code="TI" ... (2 Replies)
Discussion started by: bghosh
2 Replies

5. UNIX for Advanced & Expert Users

Sendmail Script don't deliver mails

Hi, i've got a problem with a sendmail script, which sends HTML mails. Some mail will rejected by the mail server, because the fqdn doesn't exist. Where can i set the sender-domainname by sendmail? My mail server say: "Sender address rejected: Domain not found;", which is correct... (3 Replies)
Discussion started by: rainbowwarrior
3 Replies

6. Shell Programming and Scripting

Self referencing script error message

Hello again all. I have a user editable script that I'd like to have point out the user error to. Problem is I'm having troubles getting an echoed error message to give me the line. Here's what I'm trying to do. grep -n $loc /this/script.sh where '$loc' is the argument passed to the script.... (9 Replies)
Discussion started by: DC Slick
9 Replies

7. Shell Programming and Scripting

Nightly job error message when trying to execute script

Hello All, I am getting the following error message when trying to execute the following script. AWK=/usr/bin/awk TR=/usr/bin/tr SED=/usr/bin/sed CAT=/usr/bin/cat MAILFILE=/home//nightly_jobs.tmp mailto=xxx@gmail.com Nigh_Status = `db2 "select TYPE from ETL.LOCK where STATUS <> 0 and... (12 Replies)
Discussion started by: NARESH1302
12 Replies

8. Shell Programming and Scripting

Suppress error message in shell script

Hi All this is a simple script #! /bin/bash FileCnt=`ls -lrt $DIR/* | wc -l` echo $FileCnt how could i escape the error msg if there are no files in $DIR ls: /home/sayantan/test/files/cnt/*: No such file or directory 0 Looking forward for a quick reply Regards, Newbie... (3 Replies)
Discussion started by: newbie07
3 Replies

9. Shell Programming and Scripting

Error message while executing the shell script

Hi All, When I am trying to execute the below shell script I got this error message. script ========== #!/bin/bash /usr/java/jdk1.5.0_10/bin/java - classpath /var/lib/asterisk/agi-bin/mysql-connector-java-3.0.15-ga-bin.jar/: /var/lib/asterisk/agi-bin/jarfiles:... (4 Replies)
Discussion started by: ajayyaduwanshi
4 Replies

10. Shell Programming and Scripting

problem with script and syntax error message

Hi I have the following script and have problem debugging the problems. The function of this script is to make sure the entire file is being received (the filesize of a data is not changing after 20 seconds) and start moving the file to another directory. This script should be started every 30mins.... (5 Replies)
Discussion started by: ReV
5 Replies
Login or Register to Ask a Question