STATUS ÜBERPRÜFEN
I AM LISTENING TO
|

Cron / Crontab Tips Collection

4. Oktober 2024
.SHARE

Table of Contents

I will use this article to collect interesting tips and tricks about using the Linux cron. This is not so much about setting up a cron, but about little things I use or discovered!

What is a cron ?

The cron daemon is a long-running process that executes commands at specific dates and times. You can use this to schedule activities, either as one-time events or as recurring tasks.

What is the crontab?

For commands that need to be executed repeatedly (e.g., hourly, daily, or weekly), you can use the crontab command. The crontab command creates a crontab file containing commands and instructions for the cron daemon to execute.

Format is: MIN HOUR DOM MON DOW CMD
Minute field
Hour field
Day of month
Day of week
Command

crontab -l    		# Viewing the cronjobs as currently logged in user 
crontab -e    		# Edit the cronjob for currently logged in user
crontab -l -u $USER 	# View the cronjob for the specified user 
crontab -e -u $USER	$ Edit the cronjob for the specified user

Run every 5 minutes

*/5 * * * *  /home/reggaenights/script.sh

Run yearly, monthly, weekly, daily or on reboot.
@yearly will run at 00:00 on Jan 1st for every year.
@monthly will run at 00:00 on 1st of every month.
@weekly will run at 00:00 on starting of every week.
@daily will run at 00:00 on every day.
@reboot  will run after the server has been rebooted

@yearly  	/home/reggaenights/script.sh	
@monthly 	/home/reggaenights/script.sh
@weekly		/home/reggaenights/script.sh
@daily  	/home/reggaenights/script.sh

TIPS

1. Send cron output via email

*/30 * * * * /bin/bash /cleanup | /usr/bin/mail -s "Notify me" your@email.org

2. Use a real cron for WordPress

A real cron does not rely on website activity and executes independently.

*/30 * * * * /usr/bin/wget -q -O - https://yourwordpress.org/wp-cron.php?doing_wp_cron

Do not forget to disable the virtual WordPress Cron in the wp-config.php!

define('DISABLE_WP_CRON', true);

3. Prevent Emails being sent, when cron executes > /dev/null 2>&1

*/30 * * * * /usr/bin/wget -q -O - https://yourcrone.org/wp-cron.php?doing_wp_cron >/dev/null 2>&1

4. Set Standard Variables

# Email to send output to
MAILTO="a@b.com,b@b.com"

# Setup your path for reuse
PATH="/usr/bin:/sbin:/bin"

# Tells which directory the cron should execute the crontab commands from
HOME="/path/to/app/root"

#Set the default shell
SHELL="/bin/bash"

5. Output Redirection

*/15 * * * * /home/reggaenights/script.sh >> /home/collect/cron/output/pipe.log 2>&1

TOOLS

  1. Crontab UI (NodeJS) – Easy way to edit your crontab visually. @Github
  2. Chronis ( >= PHP 7) – Chronis will help you define cron jobs using natural language / YAML and will generate the crontab files for you. @Github
  3. PHP Cron Expression Parser – Standard (V7) compliant crontab expression parser/validator with support for time zones. @Github
  4. PhpGt/Cron (PHP) – Define background jobs in standard crontab format and the Cron Runner will execute them when they are due. Jobs can be either normal scripts, or calls to static functions with automatic autoloading taken care of. @Github
  5. Cronicle (NodeJS) – A simple, distributed task scheduler and runner with a web based UI. @GitHub / Website
Let’s Talk!

Looking for a reliable partner to bring your project to the next level? Whether it’s development, design, security, or ongoing support—I’d love to chat and see how I can help.

Get in touch,
and let’s create something amazing together!

RELATED POSTS

Font licensing is wild. Proxima Nova — one of the most-used typefaces on the entire web — will run you $65 per style, and a full family license easily clears $300. Futura? Brandon Grotesque? Circular (yes, Spotify’s font)? We’re talking hundreds of dollars before you’ve typed a single character. For personal projects, indie dev work, […]

So you want to set up email on a subdomain. Maybe you’re trying to route support@help.yourdomain.com to your helpdesk, or you want newsletters@mail.yourdomain.com to run through your ESP without torching your main domain’s reputation. Whatever the reason, you’ve landed on the right page. MX records for subdomains are one of those DNS topics that seem […]

If you have ever embedded an audio player on a podcast site, a music portfolio, or a media archive, you have probably noticed that pretty rendered waveform behind the playhead. Libraries like Wavesurfer.js and Peaks.js can draw those visuals on the client, but decoding a 60-minute MP3 in the browser is slow, memory-hungry, and unreliable […]

Alexander

I am a full-stack developer. My expertise include:

  • Server, Network and Hosting Environments
  • Data Modeling / Import / Export
  • Business Logic
  • API Layer / Action layer / MVC
  • User Interfaces
  • User Experience
  • Understand what the customer and the business needs


I have a deep passion for programming, design, and server architecture—each of these fuels my creativity, and I wouldn’t feel complete without them.

With a broad range of interests, I’m always exploring new technologies and expanding my knowledge wherever needed. The tech world evolves rapidly, and I love staying ahead by embracing the latest innovations.

Beyond technology, I value peace and surround myself with like-minded individuals.

I firmly believe in the principle: Help others, and help will find its way back to you when you need it.