LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-02-2008, 05:43 PM   #1
kasthana
LQ Newbie
 
Registered: May 2008
Posts: 7

Rep: Reputation: 0
Question Check for Success of SFTP transfer using expect


Hi

I wrote an expect script to transfer some files between two machines.
I am calling this expect script through another shell script.

I want to know the status of transfer and delete the files from local machine which were successfully transferred.

My expect script is working just fine but I am unable to check the status of transfer.

Thanks
 
Old 06-03-2008, 09:49 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Why not just use scp and test the return value? e.g.

Code:
#!/bin/bash

scp /source/file user@host:/destination/directory/
if [ $? -eq 0 ]; then
    echo "It worked"
else
    echo "Oh noes.  I has erorz"
fi
 
Old 06-03-2008, 09:52 AM   #3
kasthana
LQ Newbie
 
Registered: May 2008
Posts: 7

Original Poster
Rep: Reputation: 0
Question ??

Thanks for response !! I am bound to use SFTP and that too using expect coz I can't exchange keys to make it passwordless. Could you tell me how can I check for the transfer status using SFTP and the above mentioned scenario.

thanks
 
Old 06-03-2008, 10:26 AM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Well, firstly I must say that putting passwords in an expect script is almost always a terrible idea, both from a security and maintainability standpoint.

Here's an example expect script for using FTP: link. The trick to detecting if it was a success or not is to know what the failure error message might look like, and have an expect clause for it. If you detect an error, call
Code:
exit 1
Then, in your shell script, test $? as in the example with scp above.
 
Old 06-03-2008, 10:55 AM   #5
kasthana
LQ Newbie
 
Registered: May 2008
Posts: 7

Original Poster
Rep: Reputation: 0
Question

Thx for reply.. Can I get the contents of ls on remote machine in some variable ( in my expect script) and then get that variable accesses in my shell script.
 
  


Reply



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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
transfer file using expect and sftp tanveer Linux - General 7 05-16-2008 10:29 AM
autmate file transfer using expect newbie_adm Linux - Newbie 1 07-10-2007 02:37 PM
Can transfer only 2MB using sftp nIMBVS Debian 1 11-26-2005 03:26 PM
sftp: how to transfer the whole directory? kpachopoulos Linux - General 1 11-06-2005 08:44 AM
Poor file transfer speed with sftp six6 Fedora 3 07-29-2004 12:22 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration