Reputation: 31
Could you please help me in writing a sample code to connect the remote system (through ssh) using expect in shell script.
Please find sample piece of code written as given below..
#!/bin/bash
HOST="148.147.179.118"
USER="root"
PASS="spirit"
expect -c "
# exp_internal 1 # uncomment for debugging
spawn ssh root@$HOST
expect {
"*password:*" { send $password\r\n; interact }
eof { exit }
}
exit
"
Am getting the error "*Command not found *, prompting for password, connecting to the system after giving password but not returning from the remote system.
Can anyone help me with some solution.
Upvotes: 0
Views: 3585
Reputation: 4495
Among other things, let me note that you have " marks inside the script, so you can't actually expect to package the whole thing up inside " marks can you?
Might I suggest the use of shell "HERE" documents instead? Read the shell man page for the <<
operator if you're not familiar with them.
Upvotes: 1