需求描述:
需要在A机器执行脚本远程运行B机器的脚本。
脚本内容:
#!/bin/bash
Ip=10.3.13.102
User=root
passWord=123456
Scripts=/root/22.sh
ping www.baidu.com -c2 >/dev/null ||(echo "无法连同外网,本脚本运行环境必须和外网相连!" && exit)
rpm -q sshpass &>/dev/null || yum -y install sshpass &>/dev/null
if [ $? -gt 0 ];then
yum -y install sshpass &>/dev/null || (echo "sshpass build error!" && exit)
fi
sshpass -p "$passWord" ssh ${User}@${Ip} -o StrictHostKeyChecking=no /bin/bash $Scripts