The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Calling expect scripts from other expect scripts seva Shell Programming and Scripting 0 04-03-2008 02:45 PM
tcl/expect calsum Shell Programming and Scripting 7 03-26-2008 01:23 AM
Expect/Tcl help? earnstaf UNIX for Dummies Questions & Answers 2 07-26-2007 11:01 AM
Expect and auto expect command arun_v Shell Programming and Scripting 0 03-29-2006 08:31 AM
Expect with tcl/tk sanjustudy Shell Programming and Scripting 0 10-10-2005 06:48 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-22-2008
melanie_pfefer melanie_pfefer is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 234
expect and ssh

hello
I installed expect on my solaris box.

now I want to execute this command on several servers as root (all of them have the same root password):

for i in 1 2 3; do ssh root@"srv"$i" ls /; done;


I want of course to skip these 2 steps:

The authenticity of host 'srv3 (172.21.26.25)' can't be established.
RSA key fingerprint is 2f:0c:4a:ee:19:e1:7e:f2:c8:f6:ac:2a:44:58:be:7b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'srv3,172.21.26.25' (RSA) to the list of known hosts.
Password:

How to do that using expect??
thanks
  #2 (permalink)  
Old 01-22-2008
sysgate's Avatar
sysgate sysgate is offline Forum Advisor  
Unix based
  
 

Join Date: Nov 2006
Location: Bulgaria
Posts: 1,323
Use the search function of the forum to select an example that will match your needs, there are lots of topics on that subject. Also, you can use "autoexpect" to achieve the same, look at its man pages.
  #3 (permalink)  
Old 01-22-2008
nitin09 nitin09 is offline
Registered User
  
 

Join Date: Jul 2007
Location: India
Posts: 14
#!/usr/bin/expect -f
spawn ssh -X root@<ip addr>
expect "password:"
sleep 1
send "password\r"
interact
  #4 (permalink)  
Old 01-22-2008
System Shock's Avatar
System Shock System Shock is offline Forum Advisor  
Registered User
  
 

Join Date: May 2006
Location: Tau Ceti V
Posts: 521
I'd first suggest you set ssh keys for passwordless connections if possible. You don't want to write down your passwd in a text file.
For what you want to do, you can follow nitin09's suggestion, although I wouldn't use
-X (no need to forward X11), make sure to expect and answer the yes/no query, and make sure that the expected string matches the prompt's case, ie., Password. Otherwise you are going to spend 5-10 seconds waiting for the time out.

This will work properly only if you have never logged in as root and all of the servers reply the same thing, i.e., "The authenticity of host XXXXX can't be established". If you have logged in to some servers you will only get a password prompt. If that's the case, you will need to create an "if" statement within your expect script that will do one thing if you get one response and another if you get a different response.
  #5 (permalink)  
Old 01-22-2008
ramen_noodle ramen_noodle is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2007
Location: Virginia, USA.
Posts: 251
Basically agreed. I've had to create a shared memory server and jump through hoops to deal with legacy services without *.equiv available in the past.

Expects RE engine is Tcl's so you can really match whatever regexp you need to get patterns within the expect body. exp_internal 1 is your friend and there are plenty of smart people out at comp.lang.tcl to help you if you run into problems that seem insuperable.
Closed Thread

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:55 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0