ssh远程到目标机器执行命令shell脚本
2017-06-30 09:50
816 查看
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
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
相关文章推荐
- ssh远程执行命令方法和Shell脚本实例
- 使用shell脚本ssh远程执行命令,使用awk时总是报错
- 利用shell脚本执行ssh远程另一台主机执行命令并返回命令的结果集
- shell脚本ssh到其它机器上执行命令
- ssh远程执行命令方法和Shell脚本实例
- linux 通过shell脚本在本地执行远程机器命令
- ssh远程执行目标机器上的命令
- 一个用ssh来远程登录多台机器并执行命令的脚本
- shell技巧--ssh远程执行包含nohup命令的脚本
- Java SSH远程执行Shell脚本实现
- 最简单的非交互ssh远程执行命令expect脚本
- SSH远程连接执行shell脚本
- 很实用的sh脚本,【批量文件替换】【ssh远程命令执行】【统计某一目录下面所有文档总行数】等
- Java SSH远程执行Shell脚本实现
- Linux下使用SSH非交互式远程执行命令脚本
- Java SSH远程执行Shell脚本实现(转)
- Java实践 — SSH远程执行Shell脚本
- SSH在本地执行远程机器上的命令
- Linux下非交互式远程执行命令脚本(比ssh更好的方式)
- Linux下使用SSH非交互式远程执行命令脚本