How to use SSH to run a local shell script on a remote machine?

前端 未结 17 1781
南笙
南笙 2020-11-21 22:33

I have to run a local shell script (windows/Linux) on a remote machine.

I have SSH configured on both machine A and B. My script is on machine A which will run some o

17条回答
  •  攒了一身酷
    2020-11-21 22:40

    This bash script does ssh into a target remote machine, and run some command in the remote machine, do not forget to install expect before running it (on mac brew install expect )

    #!/usr/bin/expect
    set username "enterusenamehere"
    set password "enterpasswordhere"
    set hosts "enteripaddressofhosthere"
    spawn ssh  $username@$hosts
    expect "$username@$hosts's password:"
    send -- "$password\n"
    expect "$"
    send -- "somecommand on target remote machine here\n"
    sleep 5
    expect "$"
    send -- "exit\n"
    

提交回复
热议问题