shell脚本-批量执行机器命令
场景:通过跳板机,批量获取线上机器日志
使用方式:run2 host 'ls -al /home/admin/'
#! /bin/sh
USER_NAME=$USER
if [ $# -ne 2 ]; then
echo "eg:run hostfile \"cmd\""
exit -1
fi
HOST=$1
CMD=$2
echo ""
echo "*****CMD*******"
echo "$CMD"
echo ""
while read line
do
echo "=================================================================== "
echo "$line doing"
ssh $line <<EOF
$CMD
EOF
done < $HOST