crontab

Mac crontab: Creating MacOS startup jobs with crontab, er, launchd

Table of Contents1 - macOS: crontab, launchd, and launchctl2 - Running a simple command every minute with Mac launchd3 - 1) Move to the $HOME/Library/LaunchAgents directory4 - 2) Create a Mac plist file to describe your job5 - 3) Tell MacOS about your Mac plist launchd file6 - 4) How Mac launchd works with system reboots7 - An important note about root and sudo access8 - MacOS launchd, launchctl, and plist resources9 - MacOS startup jobs: cron and crontab, launchd and launchctl

MacOS crontab FAQ: How do I run a Unix job (or shell script) through the MacOS crontab facility? I keep trying to edit my Mac crontab file, but my Mac won't save my crontab changes, or run my program.

Back to top

macOS: crontab, launchd, and launchctl

Way back when (~2012-2014), I found that the Mac crontab command was deprecated on MacOS, and the Apple documentation encouraged you to use their launchd facility. Here’s a blurb from Apple's crontab man page:

“Darwin note: Although cron(8) and crontab(5) are officially supported under Darwin, their functionality has been absorbed into launchd(8), which provides a more flexible way of automatically executing commands. See launchctl(1) for more information.”

Format of the Linux crontab date and time fields

I’ve written several things about the Linux cron command and crontab file format before, and as a quick note, here’s some information on the format of the crontab date and time fields.

Crontab date/time fields

First, from the crontab man page documentation:

A Linux shell script (and commands) to find large files

I made a mistake in configuring logrotate on a new Linux system, and almost ran into a problem because of that. Fortunately I saw the problem before it became a BIG problem, but as a result, I decided to add a script to my Linux system to check for large files, typically log files that have grown out of control for one reason or another.

Here then is a simple Linux shell script I named LargeFileCheck.sh, which searches the filesystem for files that are larger than 1GB in size:

Linux crontab examples (every X minutes or hours)

Table of Contents1 - Linux crontab: How to run a command every minute2 - Descriptions of the crontab date/time fields3 - Run a crontab command every hour4 - Run a crontab entry every day5 - Run a crontab entry every 5 minutes6 - Unix and Linux “crontab every” summary7 - Unix and Linux crontab reference information

Linux crontab FAQ: How do I schedule Unix or Linux crontab jobs to run at intervals, like “Every five minutes,” “Every ten minutes,” “Every half hour,” and so on?

Solution: I’ve posted other Unix and Linux crontab tutorials here before (How to edit your Linux crontab file, Example Linux crontab file format), but I’ve never included a tutorial that covers the “every” options, so here are some examples to demonstrate this crontab syntax.

A MySQL database backup (mysqldump) shell script

MySQL database backup FAQ: Can you share a Linux shell script that I can use to make a MySQL backup (i.e., a shell script that wraps the mysqldump command)?

I currently have a collection of websites on several different servers (including GoDaddy and A2 Hosting web servers), so I was just spending some time trying to automate my MySQL database backups. To that end, I just created a MySQL shell script that I use on each Linux server to make my database backups, and I thought I'd share that script here.

Mac launchctl StartInterval not working

It looks like the Mac launchd launchctl StartInterval is broken in Mac OS X 10.6.x, at least the current version (10.6.7). When I run a Mac launchctl script like this, which used to work just fine:

A shell script to download a URL (and test website speed)

I've been having a problem with a GoDaddy website lately (see my GoDaddy 4GH performance problems page, and in an effort to get a better handle on both (a) GoDaddy website downtime and (b) GoDaddy 4GH performance, I wrote a Unix shell script to download a sample web page from my website.

To that end, I created the following shell script, and then ran it from my Mac every two minutes:

MacOS ‘launchd’ examples (launchd plist example files)

Mac OS X launchd FAQ: Can you share some Mac launchd examples (also written as launchd plist examples, or launchctl examples)?

In an earlier tutorial (Mac OS X startup jobs with crontab, launchctl, and launchd) I demonstrated how to use the Mac OS X launchd facility instead of cron to run what would normally be a cron (crontab) job. As I started working with launchd and launchctl, I realized it would probably be helpful to see several different launchd examples, specifically launchd plist file examples.

A Linux crontab mail command example

Linux crontab mail FAQ: Can you share an example of a Linux crontab entry you use to send email on a regular basis?

Here's the source code for a really simple Linux mail script that I used to send an email message to one of my co-workers every month. This script used the Unix or Linux mail command to email a file to her that showed a list of all the websites on our server that she needed to bill our customers for.

Here's the source code for the email shell script: