今天,在公司服务器上使用脚本远程启动flume:
#!/bin/sh for ip in 10.153.140.253; #for ip in 10.153.140.250 10.153.140.251 10.153.140.252 10.153.140.253 10.153.140.254 10.153.140.255; do ssh root@$ip "ps -ef | grep java | grep -v grep |cut -c 9-15 | xargs kill -9" ssh root@$ip "rm -rf /usr/local/apache-flume-1.7.0-bin/lib/ttbrain-log-flume-sink-jar-with-dependencies.jar" scp ./ttbrain-log-flume-sink-jar-with-dependencies.jar root@$ip":/usr/local/apache-flume-1.7.0-bin/lib/" ssh root@$ip "nohup flume-ng agent -c /usr/local/apache-flume-1.7.0-bin/conf -f /usr/local/apache-flume-1.7.0-bin/conf/engine-api-log.conf -n agent1 >/dev/null 2>&1 &" done
看脚本里倒数第二行,逻辑很简单,通过ssh root@$ip 的方式远程执行命令,但是会报如下错误:
scp_lib.sh: line 10: nohup flume-ng agent -c /usr/local/apache-flume-1.7.0-bin/conf -f /usr/local/apache-flume-1.7.0-bin/conf/engine-api-log.conf -n agent1 >/dev/null 2>&1 &: No such file or directory
后来,经过检查,使用下面的方式,成功:
#!/bin/sh for ip in 10.153.140.253; #for ip in 10.153.140.250 10.153.140.251 10.153.140.252 10.153.140.253 10.153.140.254 10.153.140.255; do ssh root@$ip "ps -ef | grep java | grep -v grep |cut -c 9-15 | xargs kill -9" ssh root@$ip "rm -rf /usr/local/apache-flume-1.7.0-bin/lib/ttbrain-log-flume-sink-jar-with-dependencies.jar" scp ./ttbrain-log-flume-sink-jar-with-dependencies.jar root@$ip":/usr/local/apache-flume-1.7.0-bin/lib/" echo "nohup flume-ng agent -c /usr/local/apache-flume-1.7.0-bin/conf -f /usr/local/apache-flume-1.7.0-bin/conf/engine-api-log.conf -n agent1 >/dev/null 2>&1 &" | ssh -T $ip done原文链接:https://www.f2er.com/bash/391611.html