I have a Ubuntu 16.04.2 LTS cloud server online 24/7. There are many cronjob running on this server. There is a news website that I want to save a timestamped version of the cover page of every 20 minutes. I have created a WGET statement that runs perfectly from the command line.

wget --convert-links --output-document=/home/username/News-Headlines-$(date +%Y-%m-%d_%H:%M:%S).html news.tld

*/20 * * * * /usr/bin/wget --convert-links --output-document=/home/username/News-Headlines-$(date +%Y-%m-%d_%H:%M:%S).html news.tld

When this statement is run from the root cronjob, the file is not created and no error is produced in the /var/log/syslog

How can this WGET root cronjob statement be made to work?


An error began being mailed by cron: /bin/sh: 1: Syntax error: end of file unexpected (expecting ")")

The root crontab file does have a blank line at the end. To what is this error referring ?

  • 1
    My advice, make a script, then schedule the cronjob to execute the script on desired time interval. – fugitive Apr 8 '17 at 19:30
  • fugitive: Have you attempted to run wget in the past from root crontab ? – ml48603 Apr 8 '17 at 20:11

PROBLEM DISCOVERED The % signs were not escaped.

The following advice was found in this post: https://serverfault.com/questions/449651/why-is-my-crontab-not-working-and-how-can-i-troubleshoot-it

"Be VERY careful when using the percent (%) sign in your command. Unless they are escaped \% they are converted into newlines and everything after the first non-escaped % is passed to your command on stdin."

Once the % in the date statement were escaped \% the time stamped file was created as expected.

*/20 * * * * /usr/bin/wget --convert-links --output-document=/home/username/News-Headlines-$(date +\%Y-\%m-\%d_\%H:\%M:\%S).html news.tld

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.