Need help to handle errors during SFTP


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help to handle errors during SFTP
# 1  
Old 06-22-2011
Need help to handle errors during SFTP

Hi,

I have written a script that sftp's files from linux box to a IBM machine.

Can anybody help me how to handle any errors during SFTP file transfer.

I am writing the SFTP commands onto a file and executing that as you can see below.

Code:
while read line
do
if [[ -f ${line}".dat" ]] && [[ -f ${line}".trg" ]]; then
   echo "put "${line}".dat DMP.UPLOAD.DC4680."${line} >> sftp_queue.file
else
   echo ${line}" : no trg file associated"
fi
done < /red/wh4d/les/files/host/project/sftp.uniq >> /red/wh4d/les/files/host/sftp/sftp_log.$datetime

echo "bye" >> sftp_queue.file

sftp -b /red/wh4d/les/files/host/sftp_queue.file LIDIS@abc.light.com

Please suggest how i can get this done

Last edited by joeyg; 06-22-2011 at 02:12 PM.. Reason: Please wrap commands/data with CodeTags
# 2  
Old 06-22-2011
how about:

Code:
if ! sftp -b /path/to/file 2> sftp-errlog
then
        echo "errors during transfer:" >>/path/to/errorlog
        cat sftp-errorlog >> /path/to/errorlog
fi
rm -f sftp-errorlog

But you don't need to write to a temp file with lots and lots of separate >> redirects. Redirect larger blocks.

Code:
(
        while read line
        do
        if [[ -f ${line}".dat" ]] && [[ -f ${line}".trg" ]]; then
           # stdout goes into sftp_queue.file
           echo "put "${line}".dat DMP.UPLOAD.DC4680."${line}
        else
           # stderr goes into /red/........./sftp_log.$datetime
           echo ${line}" : no trg file associated" >&2
        fi
done 

echo "bye" ) < /red/wh4d/les/files/host/project/sftp.uniq 2>> /red/wh4d/les/files/host/sftp/sftp_log.$datetime >> sftp_queue.file

if ! sftp -b /red/wh4d/les/files/host/sftp_queue.file LIDIS@abc.light.com 2> /path/to/sftp-errorlog
then
        ( echo "Errors during transfer"
          cat /path/to/sftp-errorlog ) >> /red/..../
fi

rm -f /path/to/sftp-errorlog

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Difference between handle to the thread HANDLE and thread identifier pthread_t

This question might be silly but its confusing me a bit: What is the difference between handle to the thread HANDLE and thread identifier pthread_t? ---------- Post updated at 01:52 PM ---------- Previous update was at 01:48 PM ---------- Sorry I saw details and HANDLE is in windows and... (0 Replies)
Discussion started by: rupeshkp728
0 Replies

2. Shell Programming and Scripting

SFTP-how to log individual sftp command error while executing shell script

Hi, I have situation where i need to automate transferring 10000+ files using sftp. while read line do if ; then echo "-mput /home/student/Desktop/folder/$line/* /cygdrive/e/folder/$line/">>sftpCommand.txt fi done< files.txt sftp -b sftpCommand.txt stu@192.168.2.1 The above... (1 Reply)
Discussion started by: noobrobot
1 Replies

3. Shell Programming and Scripting

How to handle errors and warnings

Hi Guys, I am working on a shell script(main script) where in i have to call another script B and pass parameter to that script. I see that the shell script that is being called in the main script is throwing warnings/fatal errors. So i am just wondering how do i capture these and ask the script... (1 Reply)
Discussion started by: stunnerz_84
1 Replies

4. Shell Programming and Scripting

How to handle errors during script execution

Hi I have written a script which returns a number. This resulting number I assign to the variable for example: $ A=`get_dbnum 118 ttrn` $ echo ${A} 8208 $ The script becomes interective once the error occures and the number is not found. It prompts the user to enter the number. The... (1 Reply)
Discussion started by: aoussenko
1 Replies

5. Shell Programming and Scripting

trapping sftp errors

I'm trying to trap errors in a shell script executing an sftp command this way: /usr/bin/sftp $FTP_USER@$FTP_SERVER <<EOF> $HOME/$ERR_FILE cd $FTP_DIR put $FILE_NAME bye EOF I expect errors to be recorded in $ERR_FILE but they are not. The only thing in the $ERR_FILE is: sftp> sftp>... (2 Replies)
Discussion started by: pochon
2 Replies

6. UNIX for Dummies Questions & Answers

sftp: Could'nt get handle: permission denied

Hi all, I tried to google this issue but I wound up having more questions; so I'm posting here. =) I have a client who connects to my unix server via sftp to pick up a file nightly. Usually, they have no issue doing this but today was different. Here's their log: MA_OFAC_RECEIVE module:... (1 Reply)
Discussion started by: gseyforth
1 Replies

7. Shell Programming and Scripting

how to handle sql loader errors in unix

hi all, how to handle sql loader errors in unix shell ?? thanks in advance gemini (3 Replies)
Discussion started by: gemini106
3 Replies

8. UNIX for Dummies Questions & Answers

Major OS errors/Bash errors help!!!!

Hi all, dummy here.... I have major errors on entering the shell. On login I get: -bash: dircolors: command not found -bash: tr: command not found -bash: fgrep: command not found -bash: grep: command not found -bash: grep: command not found -bash: id: command not found -bash: [: =: unary... (12 Replies)
Discussion started by: wcmmlynn
12 Replies

9. AIX

Adapter Errors and Link Errors

$ errpt | more IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION 3074FEB7 0802050205 T H fscsi1 ADAPTER ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR 3074FEB7 0802050205 T H fscsi0 ADAPTER ERROR B8113DD1 ... (2 Replies)
Discussion started by: mcastill66
2 Replies

10. UNIX for Advanced & Expert Users

Adapter Errors and Link Errors

$ errpt | more IDENTIFIER TIMESTAMP T C RESOURCE_NAME DESCRIPTION 3074FEB7 0802050205 T H fscsi1 ADAPTER ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR B8113DD1 0802050205 T H fcs1 LINK ERROR 3074FEB7 0802050205 T H fscsi0 ADAPTER ERROR B8113DD1 ... (0 Replies)
Discussion started by: mcastill66
0 Replies
Login or Register to Ask a Question