2017-08-26 32 views
0

この問題は現在、私を苦労させています。Crontabは.shを実行しませんが、crontabはコマンドを実行します

Iセットアップ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」はどこに作成しますか? 'sudo'を使っているので、'/root'ディレクトリに作成されていると思います。 –

+0

ああ、...。ありがとうございました!私はそれを完全に忘れるように私を導いて、それを動作させるためにallsortsを試していた! – Bolte

+0

私の質問@MichaelOを更新しました。 – Bolte

答えて

0

オクラホマに位置されるスクリプトと同じフォルダ内の任意の出力があるようには思えませんだから私はsudoでcrontabを編集していて、そのファイルはユーザのホームフォルダに置かれていた。これが彼らが働いていなかった理由です。私自身の問題を解決しました。

この問題が発生した場合は、スクリプトに適切なパス変数を設定していない限り、ファイル出力の完全パスを指定するだけで、sudo crontab -eではなく$ crontab -eを使用してください。

+1

この回答を受け入れると、他の人は、あなたがここでさらに助けを必要としないことを読まずに知っているでしょう。 –

関連する問題