Operate three hosts through pycharm's SSH terminal, and want to output a command to be executed synchronously on the three machines
Method 1, write a script
1, first use to ssh-keygen
generate a key file.
2. ssh-copy-id -i xxx.pub HOST
Copy the public key file to the specified HOST
3. Create a hostlist
file on the current machine and write it to the machine address (xxx.xxx.xxx.xxx)
4. Write a script on the current machine (note that the path in the script needs to be changed)
#!/bin/bash
run_cmd ()
{
local hostlist=`cat /opt/k8s/work/hostlist | awk '{ print $1 }'`;
for host in $hostlist;
do
echo "=============="$host"=============="
ssh -o StrictHostKeyChecking=no -o ConnectTimeout=2 "$host" $@ ;
done
}
run_cmd $@
5, increase the execution permission of the file
6, execute the command./run_cmd date
————————————————
Original link https://blog.csdn.net/weixin_42165490/article/details/112652257
Method 2, have not tried
to useansible