首页 > 技术文章 > 使用sshpass同时更新一台ubuntu和一台CentOS

alfredsun 2019-03-26 11:35 原文

1.在ubuntu上安装sshpass

sudo apt install sshpass

2.分别在两台的root路径下放上升级脚本:

cent:/root/upgrade.sh

#!/bin/bash
yum -y update

ubuntu:/root/upgrade.sh

#!/bin/bash
apt -y update
apt -y upgrade

apt autoclean
apt autoremove

3.当前用户目录下创建remoteIP.cfg 写下两台主机的IP

4.当前用户目录下创建uniupgrade.sh

#!/bin/bash
password=yourrootpassword
user=root

for ip in $(cat /home/alfred/remoteIP.cfg)
do
    sshpass -p $password ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $user@$ip './upgrade.sh > upgrade.log 2>&1'
done

5.执行sudo ./uniuprade.sh

推荐阅读