SFTP was successfull but got return code as 1


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users SFTP was successfull but got return code as 1
# 1  
Old 06-07-2010
SFTP was successfull but got return code as 1

Hi,

I am using SFTP for transferring files to remote server. Below is the snipped i am using for my sftp program

Code:
        echo "lcd $i_localdir">/tmp/sftp_Batch
        echo "cd $i_destdir">>/tmp/sftp_Batch
        echo "put $i_filename">>/tmp/sftp_Batch
        echo "chmod 644 $i_destdir/$i_filename">>/tmp/sftp_Batch
        echo "quit">>/tmp/sftp_Batch
        sftp -b /tmp/sftp_Batch ${i_userid}@${i_host} > /tmp/sftp_Log

The problem is that i am getting return code as 1 even though the transfer is successful. The above logic is in a loop and this is not happening for every file.

Last edited by pludi; 06-07-2010 at 03:53 AM.. Reason: code tags, please...
# 2  
Old 06-07-2010
Try capturing its stderr to the logfile too to see if it prints any errors.
# 3  
Old 06-08-2010
Quote:
Originally Posted by Ankgne
Hi,

I am using SFTP for transferring files to remote server. Below is the snipped i am using for my sftp program

Code:
        echo "lcd $i_localdir">/tmp/sftp_Batch
        echo "cd $i_destdir">>/tmp/sftp_Batch
        echo "put $i_filename">>/tmp/sftp_Batch
        echo "chmod 644 $i_destdir/$i_filename">>/tmp/sftp_Batch
        echo "quit">>/tmp/sftp_Batch
        sftp -b /tmp/sftp_Batch ${i_userid}@${i_host} > /tmp/sftp_Log

The problem is that i am getting return code as 1 even though the transfer is successful. The above logic is in a loop and this is not happening for every file.
If I remember right, you can prefix any of the commands in a batch file with "-", for example "-chmod 644 $idestdir/$i_filename" to prevent "exit on error", which I think is what's going on here. Quite possibly, the file is successfully transferred, but the chmod is failing.

You might, as Corona688 suggests, change that last line to:
Code:
sftp -b /tmp/sftp_Batch ${i_userid}@${i_host} 2>&1 >>/tmp/sftp_Log

to both redirect standard output and stderr to the logfile, and also not overwrite the log file with each iteration of your loop.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

calling another script if it's contains SUCCESSFULL how?

Hi all, i'm a newbie here, I'm just wondering how can i call my second script if it's contain successfull. script1.sh how can i call my 2nd script if he contain SUCCESSFULL script2.sh SUCCESSFULL please advise, Thanks, (10 Replies)
Discussion started by: nikki1200
10 Replies

2. Shell Programming and Scripting

SFTP return Error Code 126

Hi, We are getting the following error code while connection remote server using sftp command. sftp user@serrver Warning: child process (/opt/ssh2/bin/ssh2) exited with code 126. pls Advise. (2 Replies)
Discussion started by: koti_rama
2 Replies

3. Shell Programming and Scripting

sftp return codes

sftp -v b $putlist $SFTP_ID@TARGET_SERVER How can I get a return code if fails to put the file? sftp -v b $getlist $SFTP_ID@TARGET_SERVER How can I get a return code if fails to put the file? (1 Reply)
Discussion started by: TimHortons
1 Replies

4. Shell Programming and Scripting

Script not successfull in cron

Hi, I have a script to FTP the files to other unit. Manually this script is running fine & files are getting transferred. But running the same script using crontab does not transfer files, although the cron log shows that the file was executed. PLz suggest (2 Replies)
Discussion started by: sandeep_kmehra
2 Replies

5. UNIX for Advanced & Expert Users

login partiallly successfull

Hi, I tried logging into a UNIX system with appropriate logins.. It takes lot of time to show prompt.. when i press control C it gives me the prompt.. I observed that the .cshrc file not getting executed successfully.. when i try myself sourcing .cshrc file it doesnot do it... Please let me... (1 Reply)
Discussion started by: shafi2all
1 Replies

6. UNIX for Dummies Questions & Answers

to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's

Hi All, Can anyone please let me know the syntax / how to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 'system()' function and '${?}'. I am in a process to send the mail automatically with an attachment to bulk users. I have used 'Mailx' and 'Unencode'... (0 Replies)
Discussion started by: manas6
0 Replies

7. HP-UX

How to check sqlplus command is successfull or not in HP UX?

Hi All, I am not able to check the output of sqlplus command if it fails. can any body please help me in this regard. (5 Replies)
Discussion started by: plaban.rout
5 Replies

8. UNIX for Dummies Questions & Answers

check for successfull telnet session

In either case using ksh or tcl, how can I check that I have a successfule telnet session and am being prompted with a tacacs login prompt ? :confused: DOIT () { sleep 2 echo "<tacacs name >" sleep 1 echo "<password>" echo "en" sleep 1 echo "<enable password>" echo "term length 512"... (0 Replies)
Discussion started by: sumguy
0 Replies

9. Shell Programming and Scripting

Detecting a successfull FTP connection

I have a question. My company has to send a file to another company. The cron script currently just sends the file. However, every now and then the other companies ftp server is down. I wanted to alter my script to detect if the server is up before I attempt to send the file. My idea follows #... (2 Replies)
Discussion started by: beilstwh
2 Replies

10. UNIX for Advanced & Expert Users

Return code from PL/SQL Code

Hi Guys, I was just wondering if anybody can help me with this problem. OK, how we can get a value back from PL/SQL Script (not stored procedure/function) See the below example: (for example aaa.sh) #!/bin/ksh VALUE=`sqlplus -s user/password@test_id <<EOF @xxx.sq EOF` echo $VALUE ... (7 Replies)
Discussion started by: Shaz
7 Replies
Login or Register to Ask a Question