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 [ $# -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:
$ ./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?