Expect script hangs Linux


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Expect script hangs Linux
# 1  
Old 08-04-2011
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.
Code:
#!/bin/bash
if [ $# -ne 1 ]; then
  echo "one parameter is needed: IP address of gateway"
  exit 1
fi

expect -d -c "
  spawn tftp $1
  expect \"tftp> \";
  send \"get /var/lib/tftpboot/fb0\\n\";
  expect {
    timeout {close; exit 1}
    \"tftp> \";    
  }
  send \"quit\\n\";
  #expect eof;
  close;
 "
echo RESULT_CODE $?

The problem occurs sometimes after first try of running this script, sometimes after second or third. Here is the output from my console in case of freeze:

Code:
$ ./dw_test.sh 192.168.1.122
expect version 5.43.0
spawn tftp 192.168.1.122
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {1394}

expect: does "" (spawn_id exp6) match glob pattern "tftp> "? no
tftp>
expect: does "tftp> " (spawn_id exp6) match glob pattern "tftp> "? yes
expect: set expect_out(0,string) "tftp> "
expect: set expect_out(spawn_id) "exp6"
expect: set expect_out(buffer) "tftp> "
send: sending "get /var/lib/tftpboot/fb0\n" to { exp6 }

expect: does "" (spawn_id exp6) match glob pattern "tftp> "? no
get /var/lib/tftpboot/fb0

expect: does "get /var/lib/tftpboot/fb0\r\n" (spawn_id exp6) match glob pattern "tftp> "? no

If I uncomment "expect eof;" in script, this problem does not occur. It does not occur also, when "expect eof;" is commented together with send \"quit\\n\";. Just like the tftp "quit" command caused this problem.

What is the reason for this?

Last edited by pludi; 08-04-2011 at 09:15 AM..
# 2  
Old 08-10-2011
I generate this sort of thing with autoexpect or use ssh2 scp. You did not quote the pattern. Why not just expect the prompt and let the rest just flow by? Is this a single core cpu system, that one looping expect can lock it so well Are you on an xterm, or the console as only terminal?
# 3  
Old 08-10-2011
I wouldn't expect even an infinite loop on a single core to hang linux! It's more robust than that. expect may have taken control of your terminal though.

You might be able to switch between different text terminals with ctrl-alt-f1 through ctrl-alt-f6, login and kill it from there. ctrl-alt-f7 is traditionally where the GUI resides.
# 4  
Old 08-11-2011
Try setting a longer timeout. I believe the default is 10.
Code:
set timeout 60

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Linux (Xlib) Application hangs on GetGeometry()

Hello, I was just wondering why XGetGeometry() would cause a hang in an application. In the xlib book it says any of there "Get" functions don't necessarily return immediately. Is there a way to make a it return immediately or other functions that will give me the same results. I... (1 Reply)
Discussion started by: TMurray77
1 Replies

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

3. Shell Programming and Scripting

Want to convert an expect script to binary in Linux

Does anyone know how to convert an expect script to binary in linux?. (3 Replies)
Discussion started by: John Wilson
3 Replies

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

5. Shell Programming and Scripting

Shell script runs fine in Solaris, in Linux hangs at wait command

HI, I have a strange problem. A shell script that runs fine on solaris. when i ported to linux, it started hanging. here is the core of the script CFG_FILE=tab25.cfg sort -t "!" -k 2 ${CFG_FILE} | egrep -v "^#|^$" | while IFS="!" read a b c do #echo "jobs output" #jobs #echo "jobs... (13 Replies)
Discussion started by: aksaravanan
13 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

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 ... (4 Replies)
Discussion started by: sleepy_11
4 Replies

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

9. UNIX for Advanced & Expert Users

Linux machines hangs for a short while.

Hello! I'm managing a SuSE Linux 10 server which alot of users are using as login server and also as a build server.. There is a wierd problem with it cus' it hangs for about 30seconds ever so often and then resumes like before, this is when using SSH. It's not that heavley loaded but there... (2 Replies)
Discussion started by: Esaia
2 Replies

10. 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
Login or Register to Ask a Question