2017-08-26 80 views
0

这个问题目前我发疯。crontab的将不执行.SH但的crontab会执行一个命令

我的设置与sudo crontab -e

一个crontab的内容是1 * * * * /home/bolte/bin/touchtest.sh

该文件的内容是:

#!/bin/bash touch /home/bolte/bin/test.log

它创建的文件。但下面的脚本不会运行。

#!/bin/bash 

# CHANGE THESE 
auth_email="[email protected]" 
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

+0

你想去哪儿创建'test.log'?我想它是在'/ root'目录下创建的,因为你使用'sudo'。 –

+0

哦,为了...。谢谢!我只是想尽一切办法让它工作,修修补补让我完全忘记它! – Bolte

+0

更新了我的问题@MichaelO。 – Bolte

回答

0

好所以答案是,我用sudo编辑crontab,并且这些文件位于我的用户主文件夹中。这就是他们不工作的原因。解决了我自己的问题。

如果你有这个问题,只需使用$ crontab -e命令,而不是须藤的crontab -e,并指定完整路径为您的文件输出,除非你把正确的路径变量在脚本中。

+1

当你接受这个答案,其他人就会知道不读,你不要在这里需要更多的帮助。 –