expect script hangs while waiting for the flag...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting expect script hangs while waiting for the flag...
# 1  
Old 09-21-2009
Data expect script hangs while waiting for the flag...

I am writing a script to check whether the root password is set to a special string on some solaris servers.

Normally, the manually ssh login session is as below:

$ ssh root@host1
Password:
Last login: Wed Sep 16 13:53:28 2009 from 10.1.102.13
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
#

But the script hangs with below message:

$ ./ssh_check.exp
spawn ssh root@10.1.102.13
The authenticity of host '10.1.102.13 (10.1.102.13)' can't be established.
RSA key fingerprint is ae:f9:36:bc:dc:b9:33:4d:72:a2:d7:fb:87:c7:e4:fc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.1.102.13' (RSA) to the list of known hosts.
Password:
Last login: Tue Sep 15 18:40:29 2009 from 10.1.102.13

but it seems that the program keeps wiat the "#". But due to some reason, the sign just won't come out...

Below is the code of my script:

#!/bin/expect --

set user "root"
set password "xxxx"
set dead_list ""
set missed_list ""
set timeout 15
set missed 0
set dead 1
set done 1

set server_list {"host1", "host2"}

foreach server $server_list {
spawn ssh $user@$server
set done 1
while {$done} {
expect {
"yes/no" {
send "yes\n"
set dead 1
}
-re "(P|p)assword" {
if {$missed} {
send \003
lappend missed_list $server
set missed 0
set done 0
} else {
send "$password\n"
set missed 1
}
}
"#" {
send "exit\n"
set missed 0
set dead 1
set done 0
}
"Last" {
send \003
set missed 0
set dead 1
set done 0
}
timeout {
if {$dead} {
lappend dead_list $server
set missed 0
set dead 1
set done 0
}
send \003
}
}
}
wait
}

Thanks in advance
# 2  
Old 09-21-2009
change your ssh command

from :
spawn ssh root@10.1.102.13

to:

spawn ssh -oStrictHostKeyChecking=no root@10.1.102.13

with this option, it will not ask to manually type "yes", when you ssh to a new host.
# 3  
Old 09-21-2009
it works here, thx rdcwayx....

but the issue which blocks me is still unsolved....which the script just wait "#" when i run it...

---------- Post updated at 09:44 PM ---------- Previous update was at 02:19 AM ----------

Is there anyone who can provide some suggestion on this issue?
# 4  
Old 09-22-2009
you need manually ssh to the server which has issue, and check which prompt you get.

If it is not #, you need adjust your expect script.
# 5  
Old 09-22-2009
That's the part which confuses me...

Manually ssh the server
$ ssh root@host1
Password:
Last login: Wed Sep 16 13:53:28 2009 from 10.1.102.13
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
#

But the script hangs with below message:

$ ./ssh_check.exp
spawn ssh root@10.1.102.13
Password:
Last login: Tue Sep 15 18:40:29 2009 from 10.1.102.13

I just can not get why the "#" doesn't show up as it does in the munual way.

Comparing the output difference, it seems that there is a shell launched after the login, but "expect" does not get the output....

Last edited by sleepy_11; 09-22-2009 at 03:47 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Expect script returning string following a found expect.

I'm fairly new to scripting so this might not be possible. I am using Expect with Cisco switches and need to capture the string after finding the expect request. For example, when I issue "show version" on a Nexus switch, I'm looking to capture the current firmware version: #show version ... (0 Replies)
Discussion started by: IBGaryA
0 Replies

2. Programming

Calling another expect script inside an expect script

I have an expect script called remote that I want to call from inside my expect script called sudoers.push, here is the code that is causing me issues: set REMOTE "/root/scripts/remote" ... log_user 1 send_user "Executing remote script as $user...\n" send_user "Command to execute is: $REMOTE... (1 Reply)
Discussion started by: brettski
1 Replies

3. Programming

Calling expect script inside another expect

Hi, Am very new to expect scripting.. Can You please suggest me how to call an expect script inside another expect script.. I tried with spawn /usr/bin/ksh send "expect main.exp\r" expect $root_prompt and spawn /usr/bin/ksh send "main.exp\r" expect $root_prompt Both... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

4. Shell Programming and Scripting

Trouble setting up flag ( getopt) for my script

do case $option in d ) CHEC=true;; # more option processing can go here \? ) echo "Unknown option: -$OPTARG" : ) echo "Missing option argument for -$OPTARG";; * ) echo "Unimplimented option: -$OPTARG";; esac done shift $(($OPTIND - 1)) (2 Replies)
Discussion started by: upenmishra
2 Replies

5. Shell Programming and Scripting

Expect script hangs Linux

When I run script listed below it causes my Linux to hang. When it freezes I can do totally nothing, move cursor, switch to another terminal or whatever. Linux is just not responding and the only way out I know is a hard reset of PC. #!/bin/bash if ; then echo "one parameter is needed: IP... (3 Replies)
Discussion started by: mass85
3 Replies

6. Shell Programming and Scripting

Need help with Expect script for Cisco IPS Sensors, Expect sleep and quoting

This Expect script provides expect with a list of IP addresses to Cisco IPS sensors and commands to configure Cisco IPS sensors. The user, password, IP addresses, prompt regex, etc. have been anonymized. In general this script will log into the sensors and send commands successfully but there are... (1 Reply)
Discussion started by: genewolfe
1 Replies

7. Shell Programming and Scripting

strange expect script behavior, or am i misunderstanding expect scripting?

Hello to all...this is my first post (so please go easy). :) I feel pretty solid at expect scripting, but I'm running into an issue that I'm not able to wrap my head around. I wrote a script that is a little advanced for logging into a remote Linux machine and changing text in a file using sed.... (2 Replies)
Discussion started by: v1k0d3n
2 Replies

8. Shell Programming and Scripting

Expect - Interact output hangs when large output

Hello, I have a simple expect script I use to ssh to a workstation. I then pass control over to the user with interact. This script works fine on my HP and Mac, but on my Linux Desktop, I get a problem where the terminal hangs when ever I execute a command in the interact session that requires a... (0 Replies)
Discussion started by: natedog
0 Replies

9. UNIX for Advanced & Expert Users

Script Not waiting....plz help

Hi All: I am trying to call a multi-step script from a script. here is the code #!/usr/bin/ksh util.sh <<EOF connect dump EOF I am able to run the script but it is disconnecting before the dump job is finished. The script util.sh does not provide any functionality to wait... (9 Replies)
Discussion started by: laxman123
9 Replies

10. Shell Programming and Scripting

Script not waiting for user responce

hi all, Im fairly new to scripting and am having a noobish issue. Ive got a script that checks for certain directories and if they dont exist, prompts the user to do a mkdir. heres trouble spot in the script: cat dirlsttemp.dat | while read dir; do echo "$dir does not exist, would you... (3 Replies)
Discussion started by: rdudejr
3 Replies
Login or Register to Ask a Question