My site is hosted by a hosting company which does not allow me to access the normal cron logs. I want to redirect the output and error messages to a log file in my user space. My cron commmand is
/usr/bin/curl -s "" > dev/null

I want to send the output echos and error messages to my/path/to/updateWebsite.log . Tutorials I have looked at indicate to use
/usr/bin/curl -s "" > "" 2>&1
but I cannot make this work. Can someone help me with the correct syntax?

Dani AI

Generated

Common reasons a cron redirection “doesn’t work” here: the target must be a filesystem path (not an HTTP URL), cron runs with a minimal environment so you need absolute paths, and some control panels or cron shells treat special characters (like percent signs) specially. As suggested, wrapping the call in a script is the most reliable approach; ’s suggestion to let the PHP write its own log is valid too if you can change the script and control file permissions.

A simple, robust wrapper pattern (different from the examples already posted) is to redirect both stdout and stderr at the top of the script, stamp each run, and let curl return its real exit code so you can see failures:

#!/bin/bash
LOG="/home/youruser/logs/updateWebsite.log"
exec >> "$LOG" 2>&1
echo "---- $(date '+%Y-%m-%d %H:%M:%S') ----"
 /usr/bin/curl -fsS "http://your/site/updateWebsite.php"
 echo "curl exit=$?"

Make the script executable and call it from cron by its absolute path. Use >> (append) unless you deliberately want to truncate the log. Use the full path to curl (and date/other tools) because PATH under cron is usually minimal.

Troubleshooting checklist: run the script manually as the same user to see errors, confirm the log directory is writable (correct owner/permissions), avoid bash-only redirection operators in crontab (cron typically uses /bin/sh), and remember many hosting panels will not accept redirection in the GUI command field — that’s another reason for a wrapper. Finally, avoid logging sensitive output and consider rotating the log when it grows.

Recommended Answers

All 2 Replies

You may need to modify the PHP file to directly write to the desired file.

Why not wrap the commadn you want to run in a shell script and have that redirect to file?

job.sh:

#!/bin/bash

SITE=""
LOG=""

/usr/bin/curl -s ${SITE} > ${LOG} 2>&1

and then your cron command would be:

/path/to/job.sh

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.