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

前端 未结 12 2277
礼貌的吻别
礼貌的吻别 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

    SSH and Run Multiple Commands in Bash.

    Separate commands with semicolons within a string, passed to echo, all piped into the ssh command. For example:

    echo "df -k;uname -a" | ssh 192.168.79.134
    
    Pseudo-terminal will not be allocated because stdin is not a terminal.
    Filesystem     1K-blocks    Used Available Use% Mounted on
    /dev/sda2       18274628 2546476  14799848  15% /
    tmpfs             183620      72    183548   1% /dev/shm
    /dev/sda1         297485   39074    243051  14% /boot
    Linux newserv 2.6.32-431.el6.x86_64 #1 SMP Sun Nov 10 22:19:54 EST 2013 x86_64 x86_64 x86_64 GNU/Linux
    

提交回复
热议问题