dbaspot
Tags Register FAQ Calendar Search Today's Posts Mark Forums Read

Novice needs help using Expect to automate sftp - shell

This is a discussion on Novice needs help using Expect to automate sftp - shell ; I have been struggling with a project that requires me to use sftp. After working through all the issues getting sftp working on AIX 5.3, I now need to automate the sftp process. This appears harder than it should be. ...


Home > Database Forum > Operating Systems > shell > Novice needs help using Expect to automate sftp

Reply

 

LinkBack Thread Tools Display Modes
  #1  
Old 07-13-2007, 11:03 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Novice needs help using Expect to automate sftp

I have been struggling with a project that requires me to use sftp.
After working through all the issues getting sftp working on AIX 5.3,
I now need to automate the sftp process. This appears harder than it
should be. It appears that getting past the password prompt is a
frustration everyone runs up against. After much reading, I thought
Expect was the key and I installed it. Unfortunately, it does not
seem to be working. Here is what I am trying:

# /usr/bin/expect << EOF
> spawn sftp username@sftp.site.com
> expect "password:"
> send "my_password"
> expect "sftp>"
> send "ls"
> expect "sftp>"
> send "quit"
> EOF


And here is what I am getting:

spawn sftp username@sftp.site.com
Connecting to sftp.site.com...
username@sftp.site.com's password: #

As you can see, I am still being prompted for the password. What am I
doing incorrectly?

-Thanks

Reply With Quote
  #2  
Old 07-13-2007, 12:51 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Novice needs help using Expect to automate sftp

In comp.unix.shell rsine :
> I have been struggling with a project that requires me to use sftp.

[..]

> As you can see, I am still being prompted for the password. What am I
> doing incorrectly?


Simply setup ssh keylogin and you do not need a password at all:

$ sftp localhost
Connecting to localhost...
sftp>

It is explained in the ssh man page:

man ssh
/authorized_keys

And there are probably hundreds of guides online accessible
through a web search how to set this up. Extra points for running
ssh-agent, though you should do better even with an empty pass
phrase then putting the password in a file.

Good luck

--
Michael Heiming (X-PGP-Sig > GPG-Key ID: EDD27B94)
mail: echo zvpunry@urvzvat.qr | perl -pe 'y/a-z/n-za-m/'
#bofh excuse 13: we're waiting for [the phone company] to fix
that line
Reply With Quote
  #3  
Old 07-13-2007, 01:05 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Novice needs help using Expect to automate sftp

On Fri, 13 Jul 2007 08:03:19 -0700, rsine
wrote:
>
>
> I have been struggling with a project that requires me to use sftp.
> After working through all the issues getting sftp working on AIX 5.3,
> I now need to automate the sftp process. This appears harder than it
> should be. It appears that getting past the password prompt is a
> frustration everyone runs up against. After much reading, I thought
> Expect was the key and I installed it. Unfortunately, it does not
> seem to be working. Here is what I am trying:
>
> # /usr/bin/expect << EOF
>> spawn sftp username@sftp.site.com
>> expect "password:"
>> send "my_password"

send "my_password\r"


--
Police are unsure if the same wookie is involved in Sunday's assault.
Reply With Quote
  #4  
Old 07-13-2007, 01:17 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Novice needs help using Expect to automate sftp

On Jul 13, 1:04 pm, Bill Marcum wrote:
> On Fri, 13 Jul 2007 08:03:19 -0700, rsine wrote:
>
> > I have been struggling with a project that requires me to use sftp.
> > After working through all the issues getting sftp working on AIX 5.3,
> > I now need to automate the sftp process. This appears harder than it
> > should be. It appears that getting past the password prompt is a
> > frustration everyone runs up against. After much reading, I thought
> > Expect was the key and I installed it. Unfortunately, it does not
> > seem to be working. Here is what I am trying:

>
> > # /usr/bin/expect << EOF
> >> spawn sftp usern...@sftp.site.com
> >> expect "password:"
> >> send "my_password"

>
> send "my_password\r"
>
> --
> Police are unsure if the same wookie is involved in Sunday's assault.


Bill,

I think my issue is with the password. The vendor created one with "$
$" in it ala AbCDE$$123. I know the "$" symbol has a special meaning
for Unix. How can I pass the "$$" in a password? Enclosing the
password in quotes did not help.

Reply With Quote
  #5  
Old 07-13-2007, 01:50 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Novice needs help using Expect to automate sftp

On Jul 13, 1:17 pm, rsine wrote:
> On Jul 13, 1:04 pm, Bill Marcum wrote:
>
>
>
>
>
> > On Fri, 13 Jul 2007 08:03:19 -0700, rsine wrote:

>
> > > I have been struggling with a project that requires me to use sftp.
> > > After working through all the issues getting sftp working on AIX 5.3,
> > > I now need to automate the sftp process. This appears harder than it
> > > should be. It appears that getting past the password prompt is a
> > > frustration everyone runs up against. After much reading, I thought
> > > Expect was the key and I installed it. Unfortunately, it does not
> > > seem to be working. Here is what I am trying:

>
> > > # /usr/bin/expect << EOF
> > >> spawn sftp usern...@sftp.site.com
> > >> expect "password:"
> > >> send "my_password"

>
> > send "my_password\r"

>
> > --
> > Police are unsure if the same wookie is involved in Sunday's assault.

>
> Bill,
>
> I think my issue is with the password. The vendor created one with "$
> $" in it ala AbCDE$$123. I know the "$" symbol has a special meaning
> for Unix. How can I pass the "$$" in a password? Enclosing the
> password in quotes did not help.- Hide quoted text -
>
> - Show quoted text -


Thanks for all the help. After more research, I discovered
autoexpect. Using this tool, I was able to capture all that I was
executing. Looking at the autoexpect file, I found the password
needed the dollar signs entered as "\$\$" and the "\r" needed to be
concatenated to the data (I was leaving a space between).

For all those novices like me, here is what I found to work:

expect << EOF
spawn sftp username@sftp.site.com
expect "password:"
send -- "my_pa\$\$word\r"
expect "sftp> "
send -- "ls\r"
expect "sftp> "
send -- "exit\r"
EOF


Reply With Quote
  #6  
Old 06-22-2009, 05:46 PM
Database Newbie
 
Join Date: Jun 2009
Posts: 1
AgnelCodes is on a distinguished road
Smile Re: Novice needs help using Expect to automate sftp

^ Thanks a ton. You saved my job!

I got stuck with a problem, my Team Lead has gone on vacation and I had to complete this task before he returned. For that the final step involved pulling data back using sftp. Perl sftp was not working since many perl packages weren't installed.

This method does the job and for now it is good enough.

THanks a ton man!

PS: It would certainly feel nice to get a reply after 2 years...

Take care
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
Help needed by novice trying to figure out how to use sftp Database Administrator shell 9 07-14-2007 08:13 PM
Easy question about expect Database Administrator shell 5 05-18-2007 05:05 PM
How do I setup anonymous SFTP? Database Administrator unix-admin 1 03-16-2007 09:03 PM
SSH login automation by Expect, get stucked at last step....Help!!! Database Administrator shell 17 02-17-2007 11:21 AM
sftp setup guide wanted !! Database Administrator unix-admin 2 10-07-2006 02:39 PM


All times are GMT -4. The time now is 08:20 AM.