Cron is a program which takes care of repetitive tasks in your system (macOS / Linux). You can edit Cron with command:

crontab -e

Following line sets a Ruby script (test.rb) to run every minute:

*/1 * * * * cd /Users/hujdur/Development/ruby/cronjobs && ruby test.rb

Content of the script is straight forward:

  1. If it doesn’t exist, script creates a log file (out.log)
  2. Each time when Ruby script runs, it appends a new row in the log file:
File.open("out.log","a")
{
|f| f.write("CRONJOB is runnig\n")
}

If we open up a log file with command tail -f out.log, we can follow execution of the script:

Cronjob