↑ ↓ select, Enter open, Esc close

Add a cron job that logs its output

Caution: This command changes the system. Understand what it does before you run it.

Adjust the values, the command updates live
user@server
(crontab -l 2>/dev/null; echo "*/15 * * * * /usr/bin/php /var/www/vhosts/example.com/httpdocs/wp-cron.php >> /var/www/vhosts/example.com/logs/wp-cron.log 2>&1") | crontab -

Reads the existing crontab, appends a new line and writes everything back without opening an editor. >> file 2>&1 appends normal output and error messages to the log file, so you can later see what the job did. Without redirection, cron tries to send the output by mail, which goes nowhere on many servers.

Note: Running it twice creates the job twice. Back up and check with crontab -l first; the log file must be writable by the user.

Also searched as

  • save cron job output to file
  • add cron job from command line
  • log cron job errors
  • append to crontab without editor

Related one-liners

All in Cron

Read first, then run.

The commands on myline.de act directly on servers, files and databases. A wrong path or placeholder can delete data irreversibly or make a server unreachable.

  • All commands are provided without warranty and are not tested on every system.
  • Understand what a command does before running it, and check every placeholder.
  • Make a backup first and, if possible, try it on a test system.
  • You run commands at your own risk. Liability for damages is excluded to the extent permitted by law.