#!/bin/ksh urlArray=('http://url1:port1' 'http://url2:port2' 'http://url3:port3')for url in "${urlArray[@]}" do result=`curl $url | head -1` if (echo $result | grep '<?xml' >/dev/null 2>&1); then echo Running else echo Not Running fi done
脚本的当前输出是
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent left Speed100 12980 0 12980 0 0 711k 0 --:--:-- --:--:-- --:--:-- 0Runningcurl: (6) Couldn't resolve host 'url2:port2'Not Runningcurl: (6) Couldn't resolve host 'url3:port3'Not Running
期望的输出:
RunningNot RunningNot Running解决方法 -s标志禁止输出:
$curl foocurl: (6) Couldn't resolve host 'foo'$curl -s foo$
从curl手册页:
-s/--silent Silent or quIEt mode. Don't show progress meter or error messages. Makes Curl mute.总结
以上是内存溢出为你收集整理的带有curl和grep的shell脚本全部内容,希望文章能够帮你解决带有curl和grep的shell脚本所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)