What is the cleanest way to ssh and run multiple commands in Bash?

前端 未结 12 2088
礼貌的吻别
礼貌的吻别 2020-11-22 09:14

I already have an ssh agent set up, and I can run commands on an external server in Bash script doing stuff like:

ssh blah_server "ls; pwd;"
         


        
12条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 09:25

    This can also be done as follows. Put your commands in a script, let's name it commands-inc.sh

    #!/bin/bash
    ls some_folder
    ./someaction.sh
    pwd
    

    Save the file

    Now run it on the remote server.

    ssh user@remote 'bash -s' < /path/to/commands-inc.sh
    

    Never failed for me.

提交回复
热议问题