ssh模仿ansible批量执行命令的功能

#!/bin/bash
ssh_hosts=("IP" "IP1".......)
user=root
remote_cmd="df -h"
port=22
for ip in ${ssh_hosts[*]}
do

    ssh -t $user@$ip $remote_cmd

done

其中remote_cmd改成你想执行的命令,其中控制机和被执行命令的机器做了免秘钥登录

原文地址:https://www.cnblogs.com/uglyliu/p/6202029.html