Expect script exiting too fast if used without interact.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect script exiting too fast if used without interact.
# 1  
Old 01-07-2011
Error Expect script exiting too fast if used without interact.

Hi

I'm working on an Expect script that is supposed to log-into a remote server and run some steps and exit. In the script I first spawn a 'ssh' session to the server and then after logging in I 'send' all the necessary steps ( with a '\r' at the end, so that they get automatically executed the moment they are sent to the remote process) . Some of these steps take about a min to complete and the control isn't (and shouldn't be) turned over to the expect script before completion.

Now the wierd problem is, if I end my expect script with a 'interact' statement then every single line of the script is hit and executed. But if I remove the 'interact' then most of the intermediate 'send' statements are skipped and the script all of a sudden comes to a halt. Smilie

Trouble is I dont have to use the interact statement because I want the script to finish and exit by itself and not give the control to user at the end.

I dont have much experience with expect scripting but I guess this problem is because the script is expecting the response back way-too-soon for the intermediate steps to finish and turn-around, due to which some statements are overlooked. So to put sufficient delay between send commands I used 'after' /'wait' statements in-between...but to no avail. Setting timeout to a big number also didn't help Smilie

Please let me know if there is a solution to this problem.
# 2  
Old 01-07-2011
Perhaps you could post your script ?
# 3  
Old 01-07-2011
Code:
spawn ssh $username@$server
expect -re "password:" {
   send "$password\r"
}
expect "$"
send "cd $user_dir\r"
expect "$"
send "/bnr/tools/peel/peel $context_sname\r"
expect "Peel already running" {
   exit
}
expect ">"
send "\n\r"
expect ">"
send "traceci me\r"
send "\n\r"
expect ">"
send "tabxfr\r"
send "\n\r"
expect ">"
send "setup lbrest\r"
send "\n\r"
set timeout 20
expect ">"
send "\003\r"
expect "emdebug"
send "cd table_dump\r"
expect ">"
send "go\r"
send "\n\r"
expect ">"
send "rmount hpdisk\r"
expect ">"
send "startxfr\r"
set timeout 100
expect ">" 
send "quit all\r"
expect ">"
send "bsyall noex\r"
send "y\r"
set timeout 20
expect ">"
send "\003\r"
expect "emdebug>"
send "cd ..\r"
expect ">"
send "go\r"
send "\n\r"
expect ">"
send "hpdump 'DATAFILL_smtxv19ap'\r"
interact



In the above script.. if I don't use the interact at the bottom, the statements send "rmount hpdisk\r" , expect ">", send "startxfr\r" almost always get passed over.

Last edited by Franklin52; 01-07-2011 at 06:19 AM.. Reason: please use code tags
# 4  
Old 01-07-2011
Can't remember the exact syntax now, but you can slow down the rate at which expect sends characters (send_slow?) and you can also turn on some pretty verbose debugging (exp_debug?) that allows you to see exactly what's going backwards and forwards.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Expect and interact

I am trying to log on to server as a normal user and then sudo to root. I am using below expect script. $ cat SC.orig expect <<EOF # | tee -a $LOGFILE spawn sshpass -p "mypassword" ssh -l myid nim expect "$" send "sudo su - root\n" expect "Password:" send "mypassword\n"; sleep 4... (3 Replies)
Discussion started by: sri243
3 Replies

2. Shell Programming and Scripting

Expect script - Interact help

Hi Guys, Further to my post yesterday I have got round the issue of not being able to use expect by using one of our unix machines to have the script running instead of the jumpbox itself. However my issue is I now have an extra bit it the script which is shh to the jumpbox which requires a ras... (1 Reply)
Discussion started by: mutley2202
1 Replies

3. Shell Programming and Scripting

Expect Scripting - Using the "interact" command?

Hello All, I am writing an Expect Script to execute some commands over ssh then exit the script. The script works just fine if I automate everything and assuming the correct password was entered. So this Expect Script gets executed from a Bash script... From the Bash script I pass along an... (0 Replies)
Discussion started by: mrm5102
0 Replies

4. Shell Programming and Scripting

can a nohup'ed ksh script interact with user

I have a long running ksh script that I need to run with "nohup" in the backgound which is all well and good but at the very start of the script it needes to output to the screen to query the user and accept a response before continuing. Any thoughts on how to accomplish this other than... (11 Replies)
Discussion started by: twk
11 Replies

5. Programming

How could I interact with shell script from webportal written in php?

Hello, I am new on PHP scripting .I have shell scripts which I an running currently from linux server but now I want to make a web portal from where I will run all my scripts but the problem is all my scripts ask for parameters so I am getting confused how could I run my shell script from web... (2 Replies)
Discussion started by: anuragpgtgerman
2 Replies

6. UNIX for Dummies Questions & Answers

Expect "interact" fails when called from another script

So, I have an expect script (let's call it expect.exp) that takes 3 arguments. It logs into a remote server, runs a set of commands, then hands control over to the user by the "interact" command. If I call this script from the command line, it works properly. Now I'd like to apply this script... (2 Replies)
Discussion started by: treesloth
2 Replies

7. Shell Programming and Scripting

How to make shell script interact with program

Hello all! I have a C program that runs on a loop, prompting the user for input until it is exited. I want to create a shell script that can run this program and provide input. How can I do this? I have investigated 'expect' and piping to stdin, but haven't had any success. Any help is... (2 Replies)
Discussion started by: radish04
2 Replies

8. 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

9. 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

10. Shell Programming and Scripting

can a shell script interact with database?

Hi All, Language like C,Java can interact with database..and can use database information .. can a shall script do this? if yes thn plz guide me..... thankx (7 Replies)
Discussion started by: johnray31
7 Replies
Login or Register to Ask a Question