LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 03-16-2008, 10:28 PM   #1
thefountainhead100
LQ Newbie
 
Registered: Mar 2008
Posts: 27

Rep: Reputation: 15
Unhappy How to use EXPECT command to scp or ssh?


Hi

Could someone who has used expect tell me how to use it to SCP ?

I read the manual and a tutorial and wrote and shell script as follows.

#!/usr/bin/expect --
spawn /usr/bin/scp root@192.168.1.190:/home/file /mydir/.
expect "passowrd:"
send "pwdof1.190\r"


I save it as expectcheck and type expectcheck in the command prompt after setting the path.

But it doesnot work and reverts to the command prompt after displaying the second line of the script.
What is wrong with the script?

Please do give the correct working code if possible.. Thanks

Ash

Last edited by thefountainhead100; 03-16-2008 at 10:30 PM.
 
Old 03-18-2008, 06:46 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,373

Rep: Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962
generally that looks ok, but you do have some clear typos there... they aren't in the original script are they?

here's a siilar one for reference http://bash.cyberciti.biz/security/sshlogin.exp.php
 
Old 03-26-2008, 05:26 AM   #3
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 230Reputation: 230Reputation: 230
Uh, did you paste that script into your post, or retype it? If you pasted it, there's an error in line 3:
Code:
expect "passowrd:"
should be:
Code:
expect "password:"
Any chance that's your problem?
 
Old 03-28-2008, 06:18 AM   #4
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Lenny/Squeeze/Wheezy/Sid
Posts: 4,052

Rep: Reputation: 484Reputation: 484Reputation: 484Reputation: 484Reputation: 484
Put this at the beginning of your code:

Code:
exp_internal 1
It traces all the traffic between Expect and the spawned process and it shows you all the decisions Expect makes and why.

The typo in "Passwrod" would have shown up immediately as Expect would have told you that there is no match.

jlinkels
 
Old 03-28-2008, 05:52 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,962
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
And, as always when such a question crops up:

You'd really be better off using password-less ssh authentication
than sticking passwords into scripts.



Cheers,
Tink
 
Old 03-28-2008, 06:02 PM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,373

Rep: Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962
Tink, this thread was from needing to connect to an ssh server on an embedded system which didn't support PSK's, so i suggested expect... let's be careful not to go round in circles!
 
Old 03-28-2008, 06:41 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,962
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
Quote:
Originally Posted by acid_kewpie View Post
Tink, this thread was from needing to connect to an ssh server on an embedded system which didn't support PSK's, so i suggested expect... let's be careful not to go round in circles!
Didn't say that in the post ... oh well ;}

That'll teach me not to look at everyones post
history and see that there's already three threads
of his on that topic in Kernel...

Cheers,
Tink

Last edited by Tinkster; 03-28-2008 at 06:43 PM. Reason: added snide remark
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Auto SSH-login expect script creatorrr Linux - Software 7 10-26-2011 03:09 AM
Translating windows pscp command to linux scp command help robward Linux - General 2 01-17-2008 06:02 AM
scp and ssh linderox Linux - Networking 2 11-19-2007 02:04 AM
allow ssh, scp and sftp? javier_ccs Linux - Newbie 6 09-12-2006 08:11 AM
ssh scp question shanenin Linux - Networking 3 10-14-2004 12:26 AM


All times are GMT -5. The time now is 12:33 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration