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?
# 15  
Old 09-23-2014
fretagi,
I know you've solved the problem in the meantime, but let me explain why >> /var/tmp/HLR_ftp.log is not sufficient to also redirect HLR01_21092014: No space left on device to the logfile.

With >> you are appending only stdout messages to the logfile. The "No space left ..." message is written to stderr. The solution is to redirect stderr to stdout, so stderr also goes to the logfile:
Code:
>> /var/tmp/HLR_ftp.log 2>&1

# 16  
Old 09-23-2014
Quote:
Originally Posted by gull04
Hi Fretagi,

if you add the line like so;
Code:
#!/usr/bin/sh

cd /moneta_polled01/pre_hlr

HOST=10.100.48.47
USER=hlr_dump
PASSWD=dump123

/usr/bin/ftp -nv $HOST <<EOF
user $USER $PASSWD
#cd Ordens
binary
mget *HLR*
bye
EOF
echo $? 
EXITSTATUS=$?

if [ $EXITSTATUS != "0" ] # exit status is not 0
        then
echo "No space left on device" | mailx -s "Error:No Space" xyz@mycomp.com
        else
echo "File transfered SUCCESSFULLY at $(date)." | mailx -s "HLR successfully transfered" xyz@mycomp.com

Then run your script - you'll be able to see the exit code of "ftp" which I think will be "0"

Regards

Dave
Dave,
If you add that line of code there, you completely change the remaining logic of the script. The commands:
Code:
echo $? 
EXITSTATUS=$?

Will print the exit status of the ftp command, but set EXITSTATUS to the exit status of the echo command rather than the exit status of the ftp command. If there is some reason that you think the following if is not working correctly, the way to print ftp's exit status without changing the logic of the rest of the script would be:
Code:
EXITSTATUS=$?
echo $EXITSTATUS

Note that you can't use:
Code:
EXITSTATUS=$?
echo $?

either because the echo would then be printing the exit status of the command assigning a value to the EXITSTATUS variable (which, barring significant hardware problems or lack of accessible memory, should always be zero).
# 17  
Old 09-24-2014
Hi

I have put that script in a crontab, to get the file once a week, but how do I modify the script in order to that in the next run, he would not pick all files starting with HLR. The format of the file is HLRXX_MMDDYYYY, where XX is just a number.
# 18  
Old 09-24-2014
Hi Fretagi,

Because the script has been hard coded to pickup the HLR files, you'll need to modify to pickup the files that you want for the next run.

@Don, I realise that that was the case, I just wasn't clear that the echo statement was only there for testing and should be removed afterwards - sometimes - especially when a user arrives at your desk and performs the "Headless Chicken Dance" it is difficult to be as involved with the forum as one would like.

Regards

Dave

Last edited by gull04; 09-24-2014 at 06:12 AM.. Reason: Typo
# 19  
Old 09-24-2014
Quote:
Originally Posted by fretagi
Hi

I have put that script in a crontab, to get the file once a week, but how do I modify the script in order to that in the next run, he would not pick all files starting with HLR. The format of the file is HLRXX_MMDDYYYY, where XX is just a number.
If you want just files with today's date, change:
Code:
mget *HLR*

to:
Code:
mget HLR*_$(date '+%m%d%Y')

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