Cronjob with Ruby: A simple example of Ruby usage with cronjob
Cron is a program which takes care of repetitive tasks in your system (macOS / Linux). You can edit Cron with command:
Following line sets a Ruby script (test.rb) to run every minute:
Content of the script is straight forward:
- If it doesn’t exist, script creates a log file (out.log)
- Each time when Ruby script runs, it appends a new row in the log file:
If we open up a log file with command tail -f out.log
, we can follow execution of the script: