Running a Shell Script on a Remote Machine Through SSH | Baeldung on Linux

PHOTO EMBED

Thu Jul 28 2022 04:40:07 GMT+0000 (Coordinated Universal Time)

Saved by @gistbucket #bash #expect

#!/usr/bin/expect
set timeout 60
spawn ssh [lindex $argv 1]@[lindex $argv 0]
expect "*?assword" {
    send "[lindex $argv 2]\r"
    }
expect ":~$ " {
    send "
        mkdir -p /home/tools/baeldung/auto-test;
        cd /home/tools/baeldung/auto-test;
        tree
        sshpass -p 'Baels@123' scp -r tools@10.45.67.11:/home/tools/cw/baeldung/get_host_info.sh ./;
        tree
        bash get_host_info.sh\r"
    }
expect ":~$ " {
    send "exit\r"
    }
expect eof
content_copyCOPY

bash

https://www.baeldung.com/linux/run-shell-script-remote-ssh