我的Bash脚本赢了';不要缓存项目

我的Bash脚本赢了';不要缓存项目,bash,Bash,我正在尝试使用我找到的Bash脚本,并对其进行了轻微修改,以自动更新GoDaddy上的DNS设置 它有点工作,但是我没有收到回音“没有ip地址,程序退出”,因为我认为在第28行没有创建缓存文件。有人能告诉我发生了什么事吗?我用的是拉斯比安。非常感谢 #/bin/bash # This script is used to check and update your GoDaddy DNS server to the IP address of your current internet conn

我正在尝试使用我找到的Bash脚本,并对其进行了轻微修改,以自动更新GoDaddy上的DNS设置

它有点工作,但是我没有收到回音“没有ip地址,程序退出”,因为我认为在第28行没有创建缓存文件。有人能告诉我发生了什么事吗?我用的是拉斯比安。非常感谢

#/bin/bash

# This script is used to check and update your GoDaddy DNS server to the IP address of your current internet connection.
#
# Original PowerShell script by mfox: https://github.com/markafox/GoDaddy_Powershell_DDNS
# Ported to bash by sanctus
# Added AAAA record by Binny Chan
#
# Improved to take command line arguments and output information for log files by pollito
#
# First go to GoDaddy developer site to create a developer account and get your key and secret
#
# https://developer.godaddy.com/getstarted
#
# Be aware that there are 2 types of key and secret - one for the test server and one for the production server
# Get a key and secret for the production server

# Check an A record and a domain are both specified on the command line.
if [ $# -ne 2 ]; then
    echo "usage: $0 type a_record domain_name"
    echo "usage: $0 AAAA www my_domain"
    exit 1
fi

# Set A record and domain to values specified by user
name=$1     # name of A record to update
domain=$2   # name of domain to update
cache=/tmp/.mcsync.$name.$domain.addr
[ -e $cache ] && old=`cat $cache`

# Modify the next two lines with your key and secret
key="key"      # key for godaddy developer API
secret="secret"   # secret for godaddy developer API

headers="Authorization: sso-key $key:$secret"

#echo $headers
        # Get public ip address there are several websites that can do this.
        ret=$(curl -s GET "http://ipinfo.io/json")
        currentIp=$(echo $ret | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")

# Check empty ip address or not
if [ -z "$currentIp" ]; then
        echo $name"."$domain": $(date): no ip address, program exit"
        exit 1
fi
# Check cache ip, if matched, program exit
if [ "$old" = "$currentIp" ]; then
        echo $name"."$domain": $(date): address unchanged, program exit $currentIp"
        echo "IPs equal. Exiting..."
        exit
else
        echo $name"."$domain": $(date): currentIp:" $currentIp
fi

#Get dns ip
result=$(curl -s -k -X GET -H "$headers" \
 "https://api.godaddy.com/v1/domains/$domain/records/A/$name")
        dnsIp=$(echo $result | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b")

echo $name"."$domain": $(date): dnsIp:" $dnsIp

# ip not match
if [ "$dnsIp" != $currentIp ];
 then
        echo $name"."$domain": $(date): IPs not equal. Updating."
        request='{"data":"'$currentIp'","ttl":3600}'
        #echo $request
        nresult=$(curl -i -k -s -X PUT \
 -H "$headers" \
 -H "Content-Type: application/json" \
 -d $request "https://api.godaddy.com/v1/domains/$domain/records/A/$name")
        #echo $nresult
        echo $name"."$domain": $(date): IPs not equal. Updated."
fi

否,消息位于第44行,这是因为
$currentIp
为空而编写的,这是在第39行:读取curl请求对“”的响应时检索到的

否则,只需删除缓存文件

rm /tmp/.mcsync.$name.$domain.addr

其中,
$name
$domain
被替换为脚本的第一个和第二个参数。

Hi!不幸的是,脚本在/tmp/文件夹中没有生成任何内容,我认为这就是问题所在?为什么您希望它返回
没有ip地址,程序退出
?还是会返回此消息?不清楚,;在第28行,它只将
缓存
变量分配给字符串
/tmp..
对不起。我想看到的是“地址不变,程序退出”而不是“没有ip…”-但我没有看到这个!当我运行脚本并且地址相同(未更改)时,我看不到此回音。对不起,我是新来的!在您提供的脚本中,它从未写入
$cache
文件,可能此部分已删除