5 added 138 characters in body
source | link

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 root@192.168.1.1:/root/test

ssh root@192.168.1.1 "echo 'Test' >> /root/test"

ssh -O exit root@192.168.1.1

ssh.exp:

#!/usr/bin/expect -f

# Enable some diagnostic output
exp_internal 1

spawn /usr/bin/ssh -M -N root@192.168.1.1

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 root@192.168.1.1
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
root@192.168.1.1's password:
expect: does "root@192.168.1.1'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) "root@192.168.1.1's password: "
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "root@192.168.1.1's password: "
send: sending "OMGSECRET\r" to { exp4 }
mux_client_request_session: read from master failed: Connection reset by peer
root@192.168.1.1's password:
root@192.168.1.1'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.

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 root@192.168.1.1:/root/test

ssh root@192.168.1.1 "echo 'Test' >> /root/test"

ssh -O exit root@192.168.1.1

ssh.exp:

#!/usr/bin/expect -f

# Enable some diagnostic output
exp_internal 1

spawn /usr/bin/ssh -M -N root@192.168.1.1

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 root@192.168.1.1
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
root@192.168.1.1's password:
expect: does "root@192.168.1.1'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) "root@192.168.1.1's password: "
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "root@192.168.1.1's password: "
send: sending "OMGSECRET\r" to { exp4 }
mux_client_request_session: read from master failed: Connection reset by peer
root@192.168.1.1's password:
root@192.168.1.1's password:

The SSH connection is being established, but it craps out when I try to reuse it for the SCP command. Why?

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 root@192.168.1.1:/root/test

ssh root@192.168.1.1 "echo 'Test' >> /root/test"

ssh -O exit root@192.168.1.1

ssh.exp:

#!/usr/bin/expect -f

# Enable some diagnostic output
exp_internal 1

spawn /usr/bin/ssh -M -N root@192.168.1.1

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 root@192.168.1.1
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
root@192.168.1.1's password:
expect: does "root@192.168.1.1'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) "root@192.168.1.1's password: "
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "root@192.168.1.1's password: "
send: sending "OMGSECRET\r" to { exp4 }
mux_client_request_session: read from master failed: Connection reset by peer
root@192.168.1.1's password:
root@192.168.1.1'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.

4 Try again
source | link
#!/usr/bin/bash

# Set $user, $addr, $pass, $source and $dest ...

# expect script starts the SSH master-f connection
/usrhome/Dave/bin/expect -f uploadssh.exp "$user" "$addr" "$pass"

# Next two commands should use the masterscp connection
/usrhome/Dave/bin/scp "$source"test "$user@$addrroot@192.168.1.1:$dest"

/usr/binroot/ssh -M -N "$user@$addr"test

# This command shouldssh beroot@192.168.1.1 executed"echo on'Test' remote>> server
/etc/init.droot/dnsmasq restarttest"

# Close the master connection
ssh -O exit root@192.168.1.1

uploadssh.exp:

#!/usr/bin/expect -f

# Enable some diagnostic output
exp_internal 1

# Set $user, $addr and $pass ...

spawn /usr/bin/ssh -M -N "$user@$addr"root@192.168.1.1

expect {
    -re ".*yes.*no.*" {
        exp_send "yes\r"
        exp_continue
    }
    -re ".*password.*" {
        exp_send "$pass\r""OMGSECRET\r"
    }
}

The bash script is called by PHP. I keep getting this in the Apache error log:


$ bin/upload.sh
spawn /usr/bin/ssh -M -N root@192.168.1.1
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
root@192.168.1.1's password:
expect: does "root@192.168.1.1's password: " (spawn_id exp3exp4) 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) "root@192.168.1.1's password: "
expect: set expect_out(spawn_id) "exp3""exp4"
expect: set expect_out(buffer) "root@192.168.1.1's password: "
send: sending "admin\r""OMGSECRET\r" to { exp3exp4 }
Permissionmux_client_request_session: denied,read pleasefrom trymaster again.
Permissionfailed: denied,Connection pleasereset tryby again.peer
Permission deniedroot@192.168.1.1's (publickey,password).:
lostroot@192.168.1.1's connectionpassword:

It's sending the correct password (send: sending "admin\r" to { exp3 })The SSH connection is being established, sobut it craps out when I don't know whytry to reuse it can't authenticatefor the SCP command. Why?

#!/usr/bin/bash

# Set $user, $addr, $pass, $source and $dest ...

# expect script starts the SSH master connection
/usr/bin/expect -f upload.exp "$user" "$addr" "$pass"

# Next two commands should use the master connection
/usr/bin/scp "$source" "$user@$addr:$dest"

/usr/bin/ssh -M -N "$user@$addr"

# This command should be executed on remote server
/etc/init.d/dnsmasq restart

# Close the master connection
ssh -O exit

upload.exp:

#!/usr/bin/expect -f

# Enable some diagnostic output
exp_internal 1

# Set $user, $addr and $pass ...

spawn /usr/bin/ssh -M -N "$user@$addr"

expect {
    -re ".*yes.*no.*" {
        exp_send "yes\r"
        exp_continue
    }
    -re ".*password.*" {
        exp_send "$pass\r"
    }
}

The bash script is called by PHP. I keep getting this in the Apache error log:

expect: does "root@192.168.1.1's password: " (spawn_id exp3) 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) "root@192.168.1.1's password: "
expect: set expect_out(spawn_id) "exp3"
expect: set expect_out(buffer) "root@192.168.1.1's password: "
send: sending "admin\r" to { exp3 }
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
lost connection

It's sending the correct password (send: sending "admin\r" to { exp3 }), so I don't know why it can't authenticate.

#!/usr/bin/bash

expect -f /home/Dave/bin/ssh.exp

scp /home/Dave/bin/test root@192.168.1.1:/root/test

ssh root@192.168.1.1 "echo 'Test' >> /root/test"

ssh -O exit root@192.168.1.1

ssh.exp:

#!/usr/bin/expect -f

# Enable some diagnostic output
exp_internal 1

spawn /usr/bin/ssh -M -N root@192.168.1.1

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 root@192.168.1.1
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
root@192.168.1.1's password:
expect: does "root@192.168.1.1'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) "root@192.168.1.1's password: "
expect: set expect_out(spawn_id) "exp4"
expect: set expect_out(buffer) "root@192.168.1.1's password: "
send: sending "OMGSECRET\r" to { exp4 }
mux_client_request_session: read from master failed: Connection reset by peer
root@192.168.1.1's password:
root@192.168.1.1's password:

The SSH connection is being established, but it craps out when I try to reuse it for the SCP command. Why?

3 added 2091 characters in body
source | link

I'm trying to write a bashbash script that calls an expect script to establish a master SSH connection to be used for the remaining SSH commands in the bash script. I'm a little worried about running it though because it is really confusing and I'm not sure if I'm doing it right.

~/.ssh/config:

ControlMaster auto
ControlPath ~/.ssh/control-%r@%h:%p

upload.sh:

#!/usr/bin/bash

# Set $user, $addr, $pass, $source and $dest ...

# expect script starts the SSH master connection
/usr/bin/expect -f upload.exp "$user" "$addr" "$pass"

# Next two commands should use the master connection
/usr/bin/scp "$source" "$user@$addr:$dest"

/usr/bin/ssh -M -N "$user@$addr"

# This command should be executed on remote server
/etc/init.d/dnsmasq restart

# Close the master connection
ssh -O exit

upload.exp:

#!/usr/bin/expect -f

# Enable some diagnostic output
exp_internal 1

# Set $user, $addr and $pass ...

spawn /usr/bin/ssh -M -N "$user@$addr"

expect {
    -re ".*yes.*no.*" {
        exp_send "yes\r"
        exp_continue
    }
    -re ".*password.*" {
        exp_send "$pass\r"
    }
}

The bash script is called by PHP. I keep getting this in the Apache error log:

expect: does "root@192.168.1.1's password: " (spawn_id exp3) 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) "root@192.168.1.1's password: "
expect: set expect_out(spawn_id) "exp3"
expect: set expect_out(buffer) "root@192.168.1.1's password: "
send: sending "admin\r" to { exp3 }
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
lost connection

It's sending the correct password (send: sending "admin\r" to { exp3 }), so I don't know why it can't authenticate.

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. I'm a little worried about running it though because it is really confusing and I'm not sure if I'm doing it right.

~/.ssh/config:

ControlMaster auto
ControlPath ~/.ssh/control-%r@%h:%p

upload.sh:

#!/usr/bin/bash

# Set $user, $addr, $pass, $source and $dest ...

# expect script starts the SSH master connection
expect -f upload.exp "$user" "$addr" "$pass"

# Next two commands should use the master connection
scp "$source" "$user@$addr:$dest"

ssh -M -N "$user@$addr"

# This command should be executed on remote server
/etc/init.d/dnsmasq restart

# Close the master connection
ssh -O exit

upload.exp:

#!/usr/bin/expect -f

# Set $user, $addr and $pass ...

spawn /usr/bin/ssh -M -N "$user@$addr"

expect {
    -re ".*yes.*no.*" {
        exp_send "yes\r"
        exp_continue
    }
    -re ".*password.*" {
        exp_send "$pass\r"
    }
}

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

# Set $user, $addr, $pass, $source and $dest ...

# expect script starts the SSH master connection
/usr/bin/expect -f upload.exp "$user" "$addr" "$pass"

# Next two commands should use the master connection
/usr/bin/scp "$source" "$user@$addr:$dest"

/usr/bin/ssh -M -N "$user@$addr"

# This command should be executed on remote server
/etc/init.d/dnsmasq restart

# Close the master connection
ssh -O exit

upload.exp:

#!/usr/bin/expect -f

# Enable some diagnostic output
exp_internal 1

# Set $user, $addr and $pass ...

spawn /usr/bin/ssh -M -N "$user@$addr"

expect {
    -re ".*yes.*no.*" {
        exp_send "yes\r"
        exp_continue
    }
    -re ".*password.*" {
        exp_send "$pass\r"
    }
}

The bash script is called by PHP. I keep getting this in the Apache error log:

expect: does "root@192.168.1.1's password: " (spawn_id exp3) 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) "root@192.168.1.1's password: "
expect: set expect_out(spawn_id) "exp3"
expect: set expect_out(buffer) "root@192.168.1.1's password: "
send: sending "admin\r" to { exp3 }
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
lost connection

It's sending the correct password (send: sending "admin\r" to { exp3 }), so I don't know why it can't authenticate.

2 Title
source | link
1
source | link