How can I automate running commands remotely over SSH to multiple servers in parallel?

前端 未结 20 1700
温柔的废话
温柔的废话 2020-12-12 20:03

I\'ve searched around a bit for similar questions, but other than running one command or perhaps a few command with items such as:

ssh user@host -t sudo su -         


        
20条回答
  •  Happy的楠姐
    2020-12-12 20:29

    Creates hostname ssh command of all machines accessed. by Quierati http://pastebin.com/pddEQWq2

    #Use in .bashrc
    #Use "HashKnownHosts no" in ~/.ssh/config or /etc/ssh/ssh_config 
    # If known_hosts is encrypted and delete known_hosts
    
    [ ! -d ~/bin ] && mkdir ~/bin
    for host in `cut -d, -f1 ~/.ssh/known_hosts|cut -f1 -d " "`;
      do
        [ ! -s ~/bin/$host ] && echo ssh $host '$*' > ~/bin/$host
    done
    [ -d ~/bin ] && chmod -R 700 ~/bin
    export PATH=$PATH:~/bin 
    

    Ex Execute:

    $for i in hostname{1..10}; do $i who;done
    

提交回复
热议问题