【发布时间】:2017-08-27 16:42:05
【问题描述】:
这个问题目前让我抓狂。
我用sudo crontab -e设置了一个crontab
内容为1 * * * * /home/bolte/bin/touchtest.sh
该文件的内容是:
#!/bin/bash
touch /home/bolte/bin/test.log
它创建文件。但是下面的脚本不会运行。
#!/bin/bash
# CHANGE THESE
auth_email="11111111@live.co.uk"
auth_key="11111111111111111" # found in cloudflare
account settings
zone_name="11111.io"
record_name="11111.bolte.io"
# MAYBE CHANGE THESE
ip=$(curl -s http://ipv4.icanhazip.com)
ip_file="/home/bolte/ip.txt"
id_file="/home/bolte/cloudflare.ids"
log_file="/home/bolte/cloudflare.log"
# LOGGER
log() {
if [ "$1" ]; then
echo -e "[$(date)] - $1" >> $log_file
fi
}
# SCRIPT START
log "Check Initiated"
if [ -f $ip_file ]; then
old_ip=$(cat $ip_file)
if [ $ip == $old_ip ]; then
echo "IP has not changed."
exit 0
fi
fi
if [ -f $id_file ] && [ $(wc -l $id_file | cut -d " " -f 1) == 2 ]; then
zone_identifier=$(head -1 $id_file)
record_identifier=$(tail -1 $id_file)
else
zone_identifier=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$zone_name" -H "X-Auth-E$
record_identifier=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_record$
echo "$zone_identifier" > $id_file
echo "$record_identifier" >> $id_file
fi
update=$(curl -s -X PUT "https://api.cloudflare.com/client/v4/zones/$zone_identifier/dns_records/$record_ident$
[ Read 55 lines (Warning: No write permission) ]
^G Get Help ^O Write Out ^W Where Is ^K Cut Text ^J Justify ^C Cur Pos ^Y Prev Page
^X Exit ^R Read File ^\ Replace ^U Uncut Text ^T To Linter ^_ Go To Line ^V Next Page
我一直在尝试解决为什么这段代码不会每分钟都运行,与位于/home/bolte/cloudflare-update-record.sh的脚本相同的文件夹中似乎没有任何输出
【问题讨论】:
-
你想在哪里创建
test.log?我猜它是在/root目录中创建的,因为您使用的是sudo。 -
哦,看在 ...谢谢!我只是想尽一切办法让它工作,修修补补让我完全忘记了!
-
更新了我的问题@MichaelO。
-
没关系,这是漫长的一天,因为我一直在通过 sudo crontab -e 进行编辑。我猜即使我指定了完整路径,它也无法运行并创建文件,为什么这很重要? @MichaelO。