I was developing a project(its an Intranet project for a company to check employees is working or not) in rails 4. In that I want to take the screen shots of the users logged in every 1 minute and save to server. I created methods for taking screen shot.And could save to the database.But problem is occurring in the cron tab creation. Its not executing at all. For creating crontab I used gem 'whenever', :require => false in my gem file. After that I wheneverize .it, So I got schedule.rb file.
My schedule.rb file
set :environment, 'development'
every 1.minutes do
runner "MyModel.cron_screenshot"
end
I want to check in development mode thats why I set environment to 'development'
MyModel is my model file contains this code
class MyModel < ActiveRecord::Base
has_attached_file :file_avatar, :default_url => "/files/:style/missing.jpg",
:styles => {
:thumb => "100x100#",
:small => "150x150>",
:medium => "500x500"
}
do_not_validate_attachment_file_type :file_avatar
def self.cron_screenshot
puts pwd()
result = %x{scrot}
create
end
def create
f = File.open(Rails.root.join('screenshot.png'), 'rb')
model = MyModel.new
model.file_avatar = f
model.save
end
end
I am using Ubuntu 13.04 as my operating system. When I entered command crontab -l to check I got the output as
# Begin Whenever generated tasks for: store
* * * * * /bin/bash -l -c 'cd /home/project/screenshot/image && bin/rails runner -e development '\''MyModel.cron_screenshot'\'''
# End Whenever generated tasks for: store
After one minute nothing is happening. What went wrong here?