getting error expect: spawn id exp4 not open while trying to grep
You can use a single command to do all the work required in one expect session:
expect <<-EOF > /home/file
set timeout 3
spawn ssh -oPort=port ip "zgrep error /dir/dir/file.gz.[54321] ; zgrep error /dir/dir/file1.gz.[54321] ; grep error /dir/dir/file ; grep error /dir/dir/file1"
expect "Are you sure you want to continue connecting (yes/no)?" { send "yes\r" }
expect "*password: " { send "password\r" }
expect "*#" { send "exit\r" }
EOF
You will need to modify your quotation "
marks and escape characters \
so that the remote shell does not to interpret them. There is no need to wrap the string error
in quotation marks.
issues with expect -send: spawn id exp4 not open
Figured out why.
I had generated ssh keys and copied it on to the destination machine. So there was no "Password: " prompt. Hence before send could complete, the ssh connection had closed.
I deleted the ssh keys from the destination machine and ran the script again and observed no issues
Expect script error send: spawn id exp4 not open while executing send password
I have already fix it, it was an error in dos2unix command. I had to code it again over Ubuntu for avoiding to run dos2unix command.
Expect script failed with spawn id not open when calling expect eof
- Remove
exp_continue
aftersend "exit\r"
, otherwise EOF will be consumed by theexpect { ... }
block and anotherexpect eof
would fail. - Change
lindex \$result 3
tolindex $result 3
as in the comments.
send spawn id exp4 not open error in expect
Your script has no major issues with it, not that would cause spawn
to fail like that. (The comments you have would cause problems, but are trivially fixable by using ;#
instead of #
.) Therefore your problem lies elsewhere (well, with very high probability).
I see that you are trying to control telnet with Expect on Windows. Alas, telnet is a special case that can't be controlled this way — Expect on Windows uses the system debugging facilities to intercept terminal output, but this doesn't work for executables that have special system permissions set, and telnet is one of the programs for which this is true — so you need another approach. The simplest is to get plink.exe
(which is really PuTTY for terminals/automation) and to use that (in “telnet” mode) instead of telnet.
expect complains that send: spawn id exp6 not open
Notice the "Connection closed by foreign host."
spawn telnet 192.168.1.51 -l root
expect {
"Connection closed by foreign host." {
puts "Telnet session closed unexpectedly."
puts "Please try again."
exit
}
"#"
}
With this form of the expect
command, expect is looking for two patterns, and the first one found "wins".
- if "connection closed" happens, the messages are printed and the program ends
- if "#" (your prompt) shows up, there's no specific action, so the
expect
command returns and the rest of your program can carry on
This technique is essential for efficient expect programming where you frequently have to look for multiple patterns.
Looking forward, you might expect to see "Connection closed" at any time: investigate the expect_before
command.
Related Topics
Bash Script Commands Not Working in Cron
Influxdb Not Asking for Authentication
Setting an Acpi Field in Linux
Aosp Build Error: Unrecognized Module Type "Hidl_Package_Root"
Can't Hard Link The Gitconfig File
Putting Extensions in a Certificate in Openssl
Difference Between Cp and Mv Force Overwrite
Rmpi: Cannot Use Mpi_Comm_Spawn API
Getting The New Squeak 5 to Run on 64 Bit Linux
Bash Linux - Massive Folder Rename
Linux + Ssh Limitation + Ssh at The Same Time from Multiple Machine to One Machine
Auto-Start Program at Login in Angstrom on Beagleboard
How to Simulate a Usb Printer to Lpt on Linux
How to Check If Emacs in Frame or in Terminal
Git Is Not Ignoring File Permission Changes