使用shell编写判断URL是否成功登陆的脚本

该博客展示了一段Shell脚本,脚本先定位到所在目录,若目录切换失败则输出错误信息并退出。接着清空ok.txt和err.txt文件,然后从url文件中读取URL,使用wget检测其可用性,将结果分别写入ok.txt和err.txt文件。

#!/bin/bash

dir="脚本的所在目录"
echo $dir
cd $dir
if [ $? == 0 ]
then pass
else
echo "wrong directory";exit 1
fi
[ -f $dir/ok.txt ] && echo > $dir/ok.txt
[ -f $dir/err.txt ] && echo > $dir/err.txt
while read url
do
wget --spider -q -o /dev/null --tries=1 -T 5 $url
if [ $? -eq 0 ]
then
echo $url >>$dir/ok.txt
action "$url is ok !" /bin/true
else
echo $url >>$dir/err.txt
action "$url is bad !" /bin/false
fi
done<$dir/url

转载于:https://blog.51cto.com/12942223/2397395

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值