Member-only story

Dennis O'Keeffe
4 min readJan 19, 2021

--

Heading image

Today’s post will demonstrate how to have a script automatically run as a cron job on your Mac computer using crontab.

We will demonstrate by automating a simple script to add the word “hello” onto a new line every minute and showing how we can log out stdout and stderr to a file after each run for our sake.

Getting started

We will create a .scripts folder at the root using to store our scripts to be used by crontab and create a file hello.sh to store our script:

Inside of the file hello.sh, add the following:

The above does the following:

  1. Echo “Starting script” to stdout.
  2. Append the word “hello” to the hello.txt file.
  3. Echo “Finished” to stdout.

Will all this out of the way, we can now tell crontab to run the script each minute.

--

--

Dennis O'Keeffe
Dennis O'Keeffe

No responses yet