shell列表操作&检查服务器接口是否可用

在写shell脚本时,列表是很常见的一种操作,这里以一个检查服务器接口是否可用的脚本来熟悉下列表的操作。

#!/bin/sh

ips=("172.30.111.100:7001" "172.30.111.101:7001")

urls=("/test/test1" "/test/test2")

for ip in ${ips[@]}; do
    for url in ${urls[@]}; do
        #statements
        #echo $url
        echo "$ip""$url"
        curl -X post "$ip""$url" -I | grep --color 200
    done
done

echo "**over**"

shell中的列表的每个条目中间以空格分隔,遍历时使用 ${ips[@]} 来进行遍历。

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×