Automating SFTP with Expect | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Automating SFTP with Expect

Shell Programming and Scripting


Tags
sftp script

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-12-2005
sysera sysera is offline
Registered User
 
Join Date: Feb 2004
Last Activity: 8 October 2009, 9:25 AM EDT
Posts: 92
Thanks: 0
Thanked 1 Time in 1 Post
Automating SFTP with Expect

Hello all,
I've written an automated SFTP script to work with the Expect command. It recently occurred to me however, that if the client side box does not have the known host entry for the server, it will not work correctly. So I have added an expect for the known host prompt, and that part works correctly, however, it does not seem to continue past that point to enter the password successfully if the known host file has already been configured for that particular server. I'm assuming I need some sort of timeout for the expect of the known hosts warning, or an if of sorts. I'm not sure how to go about this with expect though. Any help would be great. Below is my script:

#!/usr/bin/expect
set SYSTEM [lindex $argv 0]
set USER [lindex $argv 1]
set PASSWORD [lindex $argv 2]

set AUTOHOME "/etc/scripts/automation"
set TRIGDIR "/etc/scripts/automation/.engine_triggers"
set CTRIGDIR "/etc/scripts/automation/.client_triggers"

spawn /usr/bin/sftp $USER@$SYSTEM
expect "Are you sure you want to continue connecting (yes/no)?"
send "yes \r"
expect "password:"
send "$PASSWORD \r"
expect "sftp> "
send "put $CTRIGDIR/command $TRIGDIR \r"
expect "sftp> "
send "bye \r"
exit 0
Sponsored Links
    #2  
Old 09-16-2005
paulmac paulmac is offline
Registered User
 
Join Date: Sep 2005
Last Activity: 16 September 2005, 3:40 AM EDT
Location: Derby, Uk
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Bug Timeout

If you want the expect script to pause / wait for a certain amount of time
then just add

sleep 1

at the appropriate position

This will cause the prg to wait for 1 second.

You could also force expect into conservative mode, read the man page
on your system for information on this.

This will make the prg wait 1/10 sec between each character being sent.
Sponsored Links
    #3  
Old 09-16-2005
sysera sysera is offline
Registered User
 
Join Date: Feb 2004
Last Activity: 8 October 2009, 9:25 AM EDT
Posts: 92
Thanks: 0
Thanked 1 Time in 1 Post
Quote:
Originally Posted by paulmac
If you want the expect script to pause / wait for a certain amount of time
then just add

sleep 1

at the appropriate position

This will cause the prg to wait for 1 second.

You could also force expect into conservative mode, read the man page
on your system for information on this.

This will make the prg wait 1/10 sec between each character being sent.
Well, it doesn't seem to need a pause as far as I can tell. It seems more like it's looking for the Continue yes/no text, but if the key is already on that system, it never shows up and doesn't continue to input the password.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Issues with automating SFTP command krackjack84 Shell Programming and Scripting 3 01-04-2012 01:09 PM
Problem automating sFTP transfer using script in cron robbien UNIX for Dummies Questions & Answers 6 06-21-2010 03:40 AM
Problems when automating sftp rajhydprag Shell Programming and Scripting 0 10-28-2009 06:36 PM
Issues with automating SFTP vnparo Solaris 4 09-25-2009 05:43 PM
automating sftp script Rajeshsu Shell Programming and Scripting 1 07-27-2005 04:06 PM



All times are GMT -4. The time now is 05:13 PM.