Run Cron job using whenever gem in production server

The software utility cron is a time-based job scheduler in Unix-like computer operating systems. We can schedule cron job to run specific job in a particular date/time. For ruby we have whenever gem to run those cron job.

These are the processes to run whenever gem in remote server:

  • Install the whenever gem
  • Write your scheduler.rb file
  • Push to the remote server
  • Login to the remote server (for example with ssh)
  • See if whenever is good uploaded by running in terminal: whenever . You can see the following type result if whenever is uploaded

  • Update whenever crontab by running: whenever –update-crontab
  • Update whenever crontab with specifying rails environment
bundle exec whenever --set 'environment=staging' --update-crontab
  • Restart the server crontab (for example in Ubuntu server): sudo service cron restart
  • Check if crontab is good implemented on the server: crontab -l.  You can see the following type result after whenever implemented.

Few Important Corn Commands

Clear Crontab

$ crontab -r

Edit Crontab

$ crontab -e

List all Cronjab

$ crontab -l



Leave a Reply

Your email address will not be published. Required fields are marked *

Enter Captcha Here : *

Reload Image