Site icon New Generation Enterprise Linux

Catching cron job output before it vanishes into the ether

Cron & Task Scheduling (Cron/Systemd Timers/At)

Catching cron job output before it vanishes into the ether

🧩 The Challenge

Setting up a background job in crontab is easy until something actually breaks and you realize you have no idea what the script spit out because you forgot to redirect the stdout. I’ve wasted half an afternoon digging through logs only to realize the error was just printed to the screen and immediately deleted when the job finished.

💡 The Fix

Use a simple logger command to pipe your script output directly into the system journal. It’s way cleaner than manual log files and lets you search everything with journalctl.

* * * * * /usr/local/bin/backup-script.sh 2>&1 | logger -t backup-job

⚙️ Why It Works

By sending the file descriptor 2 to 1 and piping it into the logger utility, the system treats your script output like a native service message. It saves you the headache of managing log rotation for fifty different random scripts scattered across /var/log.

🚀 Pro-Tip: Tag your logs with something unique so you can filter them instantly with journalctl -t backup-job.

Linux Tips & Tricks | © ngelinux.com | 7/14/2026

0 0 votes
Article Rating
Exit mobile version