0

Background

I've got a QNAP NAS box running on my network and I want to run a cron job periodically to call a web page that will then update a Dynamic DNS service with my router's public IP address. I want to be able to take the outout of this PHP file and append to a log file.

For testing I've created a test.php file that just echos back some text.

Here are the relevant bits and pieces:

https://www.example.com/test.php

<?php 
echo "Hello world!\n"; 
?>

updateddns.sh

# updateddns.sh
########## Edit the following lines ##########
Logfile="/share/Public/ddns.log"
URL="https://www.example.com/test.php"
Token="lPpbyP22M1ePvthsJ0uO"
##############################################
date >> $Logfile
wget -4q -O - --post-data="auth=$Token" $URL >> $Logfile
echo "Complete" >> $Logfile

crontab (extract)

*/5 * * * * /bin/sh /share/Public/updateddns.sh

DVNK5C~Q (extract)

Fri Jan 19 10:00:00 GMT 2018
Complete
Fri Jan 19 10:05:00 GMT 2018
Complete
Fri Jan 19 10:10:00 GMT 2018
Complete
Fri Jan 19 10:15:00 GMT 2018
Complete
Fri Jan 19 10:20:00 GMT 2018
Complete
Fri Jan 19 10:25:00 GMT 2018
Complete
Fri Jan 19 10:30:00 GMT 2018
Complete

As you can see the cron job is running logs the date and the "Complete" text but nothing from the wget command. The other thing to note here is that rather than logging to ddns.log the output is logged to a file called DVNK5C~Q (when viewed in Windows) which looks like it's called ddns.log?? when viewed in a shell command window.

If I run the wget command directly from the shell prompt it works and I get "Hello world!" written out to the correct ddns.log file.

Anyone point me in the right direction here?

Thanks, Stuart.

Stuart Whiteford
  • 521
  • 7
  • 22
  • Depends how your cron is setup, but problem may be that wget command is not in the path for cron. Try to use full path to run wget in cron script. For example: /usr/bin/wget .... – voter Jan 19 '18 at 13:06
  • Using the full path (/usr/bin/wget) has the same result unfortunately. – Stuart Whiteford Jan 19 '18 at 13:32
  • 1
    Add logging to your crontab, i.e. `/5 * * * * /bin/sh /share/Public/updateddns.sh > /tmp/updtDns_cron.log 2>&1` and see if you get any error messages? ALSO, please confirm you're running all this code on your QNAP, else better describe the complete setup of this problem. FINALLY, you know about the QNAP user support forums? They may have solved this problem for your environment already. Good luck. – shellter Jan 19 '18 at 16:18

0 Answers0