Snippets Collections
#!/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
star

Thu Jul 28 2022 04:40:07 GMT+0000 (Coordinated Universal Time) https://www.baeldung.com/linux/run-shell-script-remote-ssh

#bash #expect

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension