How To Use Cron to Access Remote Script

From the shell you can use programs like wget and curl to access a remote script, however the same commands would fail when added to crontab. Here are my tips to get them to work:

  • Include the path to the executable i.e. /usr/local/bin/wget
  • Use the quiet/silent option when possible
  • If the URL you wish to use includes parameters (?var=value) enclose the URL in double or single quotes
  • Redirect output to a log file to verify operation

Here is how to use both wget  and curl within crontab:

# run every five minutes
*/5     *       *       *       *        /usr/local/bin/wget -qO /var/log/cron.wget.log "https://reubencrane.com/script.php?var=value"
# run on the hour
0       *       *       *       *       /usr/local/bin/curl -s "https://reubencrane.com/script.php?var=value" > /var/log/cron.curl.log

 

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *