检测域名有效期的 Shell 脚本

在我的 Wiki 上阅读该文:

http://maclife.net/wiki/index.php?title=%E6%A3%80%E6%B5%8B%E5%9F%9F%E5%90%8D%E6%9C%89%E6%95%88%E6%9C%9F%E7%9A%84_Shell_%E8%84%9A%E6%9C%AC 

 

检测域名有效期的 Shell 脚本

2007-11-10

闲来无事,写了个检测域名有效期的小脚本,检测完毕后将结果通过邮件发送,在 Cygwin 下测试通过 linux 下未测试,linux 下需要安装 email 邮件发送工具,email 工具可以从 http://email.cleancode.org 下载,当然你也可以改用其他邮件发送工具

目录

[隐藏]
<script type="text/javascript"> if (window.showTocToggle) { var tocShowText = "显示"; var tocHideText = "隐藏"; showTocToggle(); } </script>

使用方法

  • 将脚本中的邮件地址改为自己的邮件地址,将脚本保存到 $HOME/cron 路径下(其他路径也可以,但要修改脚本中的相应的路径)
  • 在与脚本相同的路径下创建 domain-names.txt 文件,并在里面输入你感兴趣的域名,每个域名占 1 行,域名前面加 # 的域名则不会被检测
  • 把该脚本加入到 cron 定时任务或 Windows 任务计划中,使其定期执行

代码 Code

#!/bin/bash

cd $HOME/cron

for domain in `tac domain-names.txt`
do
	if [[ "${domain:0:1}" != "#" ]]; then	# 域名前面带 # 的则忽略
		domainWhoisInfo=`whois ${domain}`
		expirationDate=`echo "${domainWhoisInfo}" | grep --max-count=1 "Expiration Date:"`
		expirationDate="${expirationDate/Expiration Date: /}"
		expirationDate=`date --date="${expirationDate}" "+%F %H:%M"`
		expirationDate="${expirationDate/00:00/}"	# 国际域名不包含时间
		beginDate_Second=`date +%s`
		endDate_Second=`date --date="${expirationDate}" +%s`
		remainDays=`expr /( $endDate_Second - $beginDate_Second /) / 86400`
		echo "${domainWhoisInfo}" | email --from-name "domain check" --subject "${domain}: ${expirationDate}, 还剩 ${remainDays} 天" YOUR_EMAIL_ADDRESS@mail-provider.com
	fi
done

domain-names.txt 样例

microsoft.com
#
#google.cn
google.com
sourceforge.net
maclife.net
#...

又见

http://bbs.chinaunix.net/thread-1013882-1-1.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值