shell脚本批量检查多个网站地址是否正常(亲手操作Linux服务器上)

注意:shell脚本是以.sh结尾的文件

1.在Linux服务器上自己随便找一个文件夹

[root@localhost ping]# vim ping.sh

2.进入文件夹后把一下代码粘贴进去,然后退出并保存


#!/bin/bash
array=(
http://www.baidu.com
http://www.jd.com
http://www.taobao.com
http://111.111.111.111
)
 
Wait(){
  echo -n "wait 3s "
  for((i=0;i<3;i++))
  do
    echo -n "."
    sleep 1
  done
  echo
}
 
CheckUrl(){
  wget -t 2 -T 5 --spider $1 &> /dev/null
  if [ $? -eq 0 ];then
    echo "check $1 is OK" 
  else
    echo "check $1 is FAILED" 
  fi
  return $?
}
 
main(){
  Wait
  for((i=0;i<${#array[*]};i++))
  do
    CheckUrl ${array[i]}
  done
  return $?
}
 
main $*

3.开启权限

[root@localhost ping]# chmod 755 ping.sh

4.在当前目录下执行文件

[root@localhost ping]# ./ping.sh

成功

扫描二维码关注公众号,回复: 3968258 查看本文章

猜你喜欢

转载自blog.csdn.net/qq_36746815/article/details/83505094