Sponsored Content
Full Discussion: Expect script hangs Linux
Top Forums Shell Programming and Scripting Expect script hangs Linux Post 302544541 by mass85 on Thursday 4th of August 2011 05:49:22 AM
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 08:15 AM..
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
script(1)							   User Commands							 script(1)

NAME
script - make record of a terminal session SYNOPSIS
script [-a] [filename] DESCRIPTION
The script utility makes a record of everything printed on your screen. The record is written to filename. If no file name is given, the record is saved in the file typescript. See WARNINGS. The script command forks and creates a sub-shell, according to the value of $SHELL, and records the text from this session. The script ends when the forked shell exits or when Control-d is typed. OPTIONS
The following option is supported: -a Appends the session record to filename, rather than overwriting it. NOTES
script places everything that appears on the screen in filename, including prompts. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ |CSI |Enabled | +-----------------------------+-----------------------------+ SEE ALSO
attributes(5) WARNINGS
script can pose a security risk when used in directories that are writable by other users (for example, /tmp), especially when run by a privileged user, that is, root. Be sure that typescript is not a link before running script. SunOS 5.11 30 Jan 2004 script(1)
All times are GMT -4. The time now is 01:12 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy