我在一个名为network_list.txt的文本文件中提到了一组服务器.如何运行服务器并运行命令并显示结果?我试过以下内容:
filename="network_list.txt" service=httpd while read -r line do name="$line" ping -c 3 $name > /dev/null 2>&1; RETVAL=$? if [ $RETVAL -ne 0 ] then echo "$name is down" else echo "$name is up and running" fi http_status=$(ssh $name ps -ef | grep -v grep | grep $service | wc -l) if [ $http_status -ne 0 ] then echo "$service is up and running in $name" else echo "$service is down in $name" fi done < "$filename"
但它在第一台服务器后停止.
谢谢 :) .
您需要在循环中将SSH命令的stdin重定向到无处可防止读取所有行.这应该这样做:
原文链接:https://www.f2er.com/bash/385863.htmlhttp_status=$(ssh $name "ps -ef | grep -v grep | grep $service | wc -l" < /dev/null)