在我的 Wiki 上阅读该文:
检测域名有效期的 Shell 脚本
2007-11-10
闲来无事,写了个检测域名有效期的小脚本,检测完毕后将结果通过邮件发送,在 Cygwin 下测试通过 linux 下未测试,linux 下需要安装 email 邮件发送工具,email 工具可以从 http://email.cleancode.org 下载,当然你也可以改用其他邮件发送工具
目录[隐藏] |
使用方法
- 将脚本中的邮件地址改为自己的邮件地址,将脚本保存到 $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 #...