UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 28th, 2013, 12:26 PM
akrp21 akrp21 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Posts: 5 akrp21 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 49 m 28 sec
Reputation Power: 0
How to trap sftp upload sucess or failure in unix ksh?

Trying to upload several files to a sftp site using a shell script (KSH) and wanted to find out if all files uploaded 100% or not. Can anyone tell me how to accomplish this?

Reply With Quote
  #2  
Old January 28th, 2013, 12:39 PM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,840 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 21 h 37 m 25 sec
Reputation Power: 1774
Does your sftp program set the exit status in a meaningful way?
Code:
$ false
$ echo $?
1
$ true
$ echo $?
0

Most programs return 0 on success, and a variety of small positive integers representing various kinds of 'problem'.
'grep' for example returns 0 for matching text, 1 for no matches, 2 for missing files.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper

Reply With Quote
  #3  
Old January 28th, 2013, 12:52 PM
akrp21 akrp21 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Posts: 5 akrp21 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 49 m 28 sec
Reputation Power: 0
Yes, it does give return codes.

But how would I know which file succeeded or not?

Do I need to run echo $? inside the sftp session or after it exits out of the sftp session?

Can you please give me a sample script.

Reply With Quote
  #4  
Old January 28th, 2013, 07:35 PM
spacebar208's Avatar
spacebar208 spacebar208 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Location: spaceBAR Central
Posts: 191 spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level)spacebar208 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 10 h 55 sec
Reputation Power: 41
You can log process and if any errors occurred parse the log file, For example:
Code:
$ cat test_sftp.sh
#!/bin/ksh
# test_sftp.sh
sftp -b /dev/stdin -o BatchMode=yes -o IdentityFile=/export/home/user/.ssh/id_rsa -o Port=22 user@host 1>sftp.log 2>&1 <<ENDSFTP
put file_does_not_exist_1.txt
quit
ENDSFTP
rc=$?
if [[ $rc != 0 ]]	then
	print "***Error occurred...$rc" `date "+%Y-%m-%d-%H.%M.%S"`
else
 print "***Successful transfer...$rc" `date "+%Y-%m-%d-%H.%M.%S"`
fi


$ test_sftp.sh
***Error occurred...1 2013-01-28-11.28.26


$ cat sftp.log
Connecting to host...
sftp> put file_does_not_exist_1.txt
File "file_does_not_exist_1.txt" not found.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > How to trap sftp upload sucess or failure in unix ksh?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap