user103134 user103134 -4 years ago 188
Bash Question

running command with expect



I have created a shell script which will automate login to a remote machine.

But I need to automate the execution of commands or shell scripts also along with this script.

What modification do I need to do with shell script for creating a directory(for example!) in the remote machine ?

#!/usr/bin/expect
set login "root"
set addr "10.3.2.0"
set pw "root"

spawn ssh -t $login@$addr
expect "$login@$addr's password:"
send "$pw\r"
interact


Thanks in advance.

Answer Source

You can simply add statements to your script:

#!/usr/bin/expect
set login "root"
set addr "10.3.2.0"
set pw "root"

spawn ssh -t $login@$addr
expect "$login@$addr\'s password:"
send "$pw\r"
expect "~" ; # put here string from your server prompt
send "mkdir some_dir\r"
interact
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download