文章目录
1. 脚本制作2. 运行脚本3. 脚本进化动态参数传递4. 运行脚本5. 脚本分解1. 脚本制作
#!/bin/bash URL_LIST=$@for URL in $URL_LIST; doFAIL_COUNT=0for ((i=1;i<=3;i++)); doHTTP_CODE=$(curl -o /dev/null --connect-timeout 3 -s -w "%{http_code}" $URL)if [ $HTTP_CODE -eq 200 ]; thenecho "$URL OK"breakelseecho "$URL retry $FAIL_COUNT"let FAIL_COUNT++fidoneif [ $FAIL_COUNT -eq 3 ]; thenecho "Warning: $URL Access failure!"fidone
2. 运行脚本
[root@localhost app]# ./8.sh retry retry retry 2Warning: Access failure![root@localhost app]#
3. 脚本进化动态参数传递
#!/bin/bash URL_LIST=$@for URL in $URL_LIST; doFAIL_COUNT=0for ((i=1;i<=3;i++)); doHTTP_CODE=$(curl -o /dev/null --connect-timeout 3 -s -w "%{http_code}" $URL)if [ $HTTP_CODE -eq 200 ]; thenecho "$URL OK"breakelseecho "$URL retry $FAIL_COUNT"let FAIL_COUNT++fidoneif [ $FAIL_COUNT -eq 3 ]; thenecho "Warning: $URL Access failure!"fidone
4. 运行脚本
[root@localhost app]# ./8.sh retry retry retry 2Warning: Access failure!
5. 脚本分解
[root@localhost app]# curl -I HTTP/1.1 200 OKAccept-Ranges: bytesCache-Control: private, no-cache, no-store, proxy-revalidate, no-transformConnection: keep-aliveContent-Length: 277Content-Type: text/htmlDate: Mon, 24 Feb 13:54:03 GMTEtag: "575e1f5c-115"Last-Modified: Mon, 13 Jun 02:50:04 GMTPragma: no-cacheServer: bfe/1.0.8.18[root@localhost app]#
[root@localhost app]# curl -o /de/dev/null -s -w "%{http_code}" http://www200[root@localhost app]#