ssh远程到目标机器执行命令shell脚本
linux下ssh到目标机器首先需要配置免密码登陆,才能执行如下脚本 hostnames服务器列表文件master.hadoopw1.hadoopw2.hadoopw3.hadoopw4.hadoop 运行shell脚本#!/bin/bashfunction usage() {echo "Wrong arguments input..."echo "Usa
·
linux下ssh到目标机器首先需要配置免密码登陆,才能执行如下脚本
hostnames服务器列表文件
master.hadoop
w1.hadoop
w2.hadoop
w3.hadoop
w4.hadoop
运行shell脚本
#!/bin/bash
function usage() {
echo "Wrong arguments input..."
echo "Usage: `basename $0` topicName handler[lookup|kill]" >&2
echo " eg: `basename $0` service_log lookup"
exit 1
}
topic_array=("service_log" "service_log_nh" "service_log_agent" "service_log_flow" \
"service_log_rec" "search_log" "user_trace" "user_trace_internal")
handler_array=("lookup" "kill")
if [ $# -lt 2 ]; then
usage
fi
topic=$1
handler=$2
## flume agent处理方式判断
if echo "${handler_array[@]}" | grep -w "$handler" &>/dev/null; then
echo "Fount process handler: $handler"
else
echo "Not found process handler: $handler ...."
usage
fi
## 判断是否为需要处理的flume agent名称
if echo "${topic_array[@]}" | grep -w "$topic" &>/dev/null; then
echo "Fount flume agent name: $topic"
else
echo "Not found flume agent name: $topic ...."
usage
fi
## 根据handler名称处理flume agent
hosts='hostnames' # hostname列表文件
while read line
do
hostname=$line
echo "================ $hostname ============="
case $handler in
lookup)
ssh root@$hostname -nq "ps -ef | grep flume | grep -w $topic | grep -v grep | wc -l"
;;
kill)
ssh root@$hostname -nq "ps -ef | grep flume | grep -w $topic |awk '{print $2}' |xargs kill -15"
;;
*)
usage
;;
esac
done < $hosts
更多推荐
已为社区贡献1条内容
所有评论(0)