
Bash
笔者家里有一台linux服务器,需要通过花生壳的DDNS定位其IP地址访问。故创建脚本如下,以解决最近出现的路由嵌入式设备不能DNS解析的问题,如果你跟我有同样的需求,欢迎参阅本教程:
1 yum包的安装
yum -y install curl
2 建立存放脚本文件夹
mkdir ~/scripts
3 创建域名解析脚本
vim ~/scripts/pusoray.sh
加入如下内容:
#!/bin/bash domain="example.cmdschool.org" user="example" pwd="pwd1" ipLog="/var/log/ip.log" nowIP=`curl -s ifconfig.co` if [ `echo $nowIP | tr -cd . | wc -c` != "3" ]; then exit 1 fi if [ `whereis nslookup | grep 'bin/nslookup' | wc -l` = "0" ]; then echo 'Please install nslookup first!' exit fi if [ `nslookup $domain | grep "$nowIP" | wc -l` = "1" ]; then echo "DNS don't need to updated, program exits!" exit fi /usr/bin/curl "http://$user:$pwd@ddns.oray.com/ph/update?hostname=$domain" echo `date +"%Y-%m-%d %H:%M:%S"`" $nowIP" >> $ipLog
注意需要更改的参数:
1)domain - 你向花生壳申请的域名 2)user - 登录花生壳的账号 3)pwd - 登录花生壳的密码
4 添加计划任务
crontab -e
加入如下内容(以下每5分钟执行一次):
*/5 * * * * sh ~/scripts/pusoray.sh
检查:
crontab -l
参考文献:
==========================================
http://open.oray.com/wiki/doku.php?id=%E6%96%87%E6%A1%A3:%E8%8A%B1%E7%94%9F%E5%A3%B3:http%E5%8D%8F%E8%AE%AE%E8%AF%B4%E6%98%8E
没有评论