Member-only story
4 min readJan 19, 2021
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:
- Echo “Starting script” to
stdout
. - Append the word “hello” to the
hello.txt
file. - Echo “Finished” to
stdout
.
Will all this out of the way, we can now tell crontab
to run the script each minute.