#!/bin/bash
ip=$1
ip_num=$(echo $ip | awk -F\. '{print NF}')
if [ $ip_num -eq 2 ]; then
ip=192.168.$ip
fi
shift
cmd=$@
if echo "$cmd" | grep -E "rm|reboot|shutdown" ; then
echo "危险命令,请登录主机执行!"
exit 1
fi
user=root
passwd=
echo "-- 处理远程主机: $ip 执行命令: $cmd"
sshpass -p $passwd ssh $user@$ip "$cmd"
标签:s2c,执行命令,ip,cmd,echo,SSH,主机,远程
From: https://www.cnblogs.com/dewan/p/17485511.html