您的位置:首页 > 运维架构 > Shell

检测域名有效期的 Shell 脚本

2008-03-14 23:34 1156 查看
在我的 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 下载,当然你也可以改用其他邮件发送工具

目录

[隐藏]

1 使用方法

2 代码 Code

3 domain-names.txt 样例

4 又见

if (window.showTocToggle) { var tocShowText = "显示"; var tocHideText = "隐藏"; showTocToggle(); }

使用方法

将脚本中的邮件地址改为自己的邮件地址,将脚本保存到 $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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: