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

前端 未结 17 1605
南笙
南笙 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 23:05

    Also, don't forget to escape variables if you want to pick them up from the destination host.

    This has caught me out in the past.

    For example:

    user@host> ssh user2@host2 "echo \$HOME"
    

    prints out /home/user2

    while

    user@host> ssh user2@host2 "echo $HOME"
    

    prints out /home/user

    Another example:

    user@host> ssh user2@host2 "echo hello world | awk '{print \$1}'"
    

    prints out "hello" correctly.

提交回复
热议问题