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

posted on 2017-12-25 12:44  西界-X  阅读(3582)  评论(0编辑  收藏  举报

导航