Let's assume that you have created a simple script called
echo Hello world >> log.txt
The script prints 'Hello world' and appends it to
You can test the script by executing:
At this point you should see a new file called
log.txt containing 'Hello world'.
To execute the script periodically, for example, one time per day, we can configure a new cron task using the
Type 'A' to edit the file and schedule the script execution time:
* * * * * [script to execute] | | | | | | | | | |__ Weekday (0 - 6) (Sunday = 0) | | | |____ Month (1 - 12) | | |______ Day (1 - 31) | |________ Hour (0 - 23) |__________ Minute (0 - 59)
Here is an example on how execute the script one time per day at 14:00:
0 14 * * * cd /Users/Erik/Desktop && sh hello.sh
Here is another example on how to execute the script one time per minute:
* * * * * cd /Users/Erik/Desktop && sh hello.sh
Press 'Esc' and type
:wq to write and quit.
To check the configured task:
At this point, you may need to allow full access to the disk to be able to allow
> System Preferences > Security & Privacy > Privacy > Full Disk Access. Click on the
+ button and allow access to
Note: this configuration may be risky, since now cron tasks have full access to your computer.
Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.