| |||||||||||
Problem with Expect in shell script Posted by johny (johny), 6 March 2008 Hai I have a shell script from where i call an expect to ssh to different host and execute the command.. expect script:- #!/usr/bin/expect -f set ip [lindex $argv 0] spawn ssh -X janab@$ip stty -echo expect {"connecting (yes/no)?" { send "yes\r" ; exp_continue } "password:" { send "pbaxsf\r"; exp_continue } "]$"{ send "df -k | grep \mnt\r" } } Shell script:- #!/bin/sh for i in falcon skylark bulbul mynah do expect janta $i #echo $i done when i run the shell script the password is not been sent and looks as below.. [janab@skylark ~]$ sh banta spawn ssh -X janab@falcon janab@falcon's password: spawn ssh -X janab@skylark janab@skylark's password: spawn ssh -X janab@bulbul What am i doing wrong here ... Please help me as this urgent.. Posted by admin (Graham Ellis), 6 March 2008 Try taking out the stty -echo so you can see what's happeningStandard text: Please do not ask for urgent or a.s.a.p. assistance here - we're not set up to provide a rapid response service, and in any case we answer questions as soon as we practically can. Customers of Well House Consultants (who host this site) are very welcome to email me if there are any truely urgent / critical issues and I will do my very best to help as quickly as I can. Freeloaders who ask me to prioritise giving them support without charge over and above my "day job" are being very cheaky! Posted by johny (johny), 7 March 2008 Hi Thank you and sorry for posting it to be urgent.. As advised have removed the line stty -echo and could get it working. But it seems to be sending the df -k command n number of times to a single host when pressed cntrl+c this gets out...but when i remove the exp_continue in the below line this will not work "*]$*" { send "df -k | grep /mnt\r"; exp_continue } Code :- #!/usr/bin/expect -f set ip [lindex $argv 0] spawn ssh -X janab@$ip expect { "*yes/no*" { send "yes\r"; exp_continue } sleep 1 "*assword:" { send "XV_4gTdo\r"; exp_continue } sleep 1 "*]$*" { send "df -k | grep /mnt\r"; exp_continue } "*]$*" { send "exit \r" } } O/p is as below... Last login: Thu Mar 6 20:49:04 2008 from falcon.kwi.intra.kyocera-wireless.com [janab@falcon ~]$ df -k | grep /mnt /dev/sda7 87722116 34512916 48681284 42% /mnt/local [janab@falcon ~]$ df -k | grep /mnt /dev/sda7 87722116 34512916 48681284 42% /mnt/local [janab@falcon ~]$ df -k | grep /mnt /dev/sda7 87722116 34512916 48681284 42% /mnt/local [janab@falcon ~]$ df -k | grep /mnt /dev/sda7 87722116 34512916 48681284 42% /mnt/local [janab@falcon ~]$ df -k | grep /mnt /dev/sda7 87722116 34512916 48681284 42% /mnt/local Please help me... Posted by johny (johny), 7 March 2008 Hi sorry for my previous post...I could get that working by the below code... #!/usr/bin/expect -f set ip [lindex $argv 0] spawn ssh -X janab@$ip expect { "*yes/no*" { send "yes\r"; exp_continue } sleep 1 "*assword:" { send "XV_4gTdo\r"; exp_continue } } expect "*]$*" send "df -k | grep \mnt\r" expect "*]$*" send "exit \r" expect eof But now what all i need is to capture the output of the df -k and write that into a file in shell script... Is this possible...? if yes please guide me through.... Regards Johny Posted by admin (Graham Ellis), 7 March 2008 The $expect_out(string) variable holds the output you require after each expect; you can open a file with open and write the contents of that variable there with putsThis page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |