I'm trying to write a bash
script that calls an expect
script to establish a master SSH connection to be used for the remaining SSH commands in the bash script.
~/.ssh/config:
ControlMaster auto
ControlPath ~/.ssh/control-%r@%h:%p
upload.sh:
#!/usr/bin/bash
expect -f /home/Dave/bin/ssh.exp
scp /home/Dave/bin/test [email protected]:/root/test
ssh [email protected] "echo 'Test' >> /root/test"
ssh -O exit [email protected]
ssh.exp:
#!/usr/bin/expect -f
# Enable some diagnostic output
exp_internal 1
spawn /usr/bin/ssh -M -N [email protected]
expect {
-re ".*yes.*no.*" {
exp_send "yes\r"
exp_continue
}
-re ".*password.*" {
exp_send "OMGSECRET\r"
}
}
$ bin/upload.sh
spawn /usr/bin/ssh -M -N [email protected]
parent: waiting for sync byte
parent: telling child to go ahead
parent: now unsynchronized from child
spawn: returns {5212}
Gate keeper glob pattern for '.*yes.*no.*' is ''. Not usable, disabling the performance booster.
Gate keeper glob pattern for '.*password.*' is '*password*'. Activating booster.
expect: does "" (spawn_id exp4) match regular expression ".*yes.*no.*"? (No Gate, RE only) gate=yes re=no
".*password.*"? Gate "*password*"? gate=no
[email protected]'s password:
expect: does "[email protected]'s password: " (spawn_id exp4) match regular expression ".*yes.*no.*"? (No Gate, RE only) gate=yes re=no
".*password.*"? Gate "*password*"? gate=yes re=yes
expect: set expect_out(0,string) "[email protected]'s password: "
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "[email protected]'s password: "
send: sending "OMGSECRET\r" to { exp4 }
mux_client_request_session: read from master failed: Connection reset by peer
[email protected]'s password:
[email protected]'s password:
The SSH connection is being established, but it craps out when I try to reuse it for the SCP command. Why?
Possible final sad edit: Alas it appears cygwin doesn't support multiplexing.
ps
at the right time. It's safe to pass the password in an environment variable ($::env(PASSWORD)
in Tcl).