Question

I cannot get this cron job to get started. I am running opsworks instances and this is my recipe:

cron "delete_error_log" do
  hour "12"
  minute "30"
  command %Q{
  sudo find /srv/www/ -name "error_log" -delete
  }
  action :create
end

I have made sure that the cron would work by running inside ssh.

The error I am getting is this:

================================================================================
Error executing action `create` on resource 'cron[delete_error_log]'
================================================================================


Chef::Exceptions::Cron
----------------------
Error updating state of delete_error_log, exit: 1


Resource Declaration:
---------------------
# In /opt/aws/opsworks/releases/20140423133810_223/site-cookbooks/cron_job/recipes/delete_error_log.rb

1: cron "delete_error_log" do
2:   hour "12"
3:   minute "30"
4:   command %Q{
5:   sudo find /srv/www/ -name "error_log" -delete
6:   }
7:   action :create
8: end


Compiled Resource:
------------------
# Declared in /opt/aws/opsworks/releases/20140423133810_223/site-cookbooks/cron_job/recipes/delete_error_log.rb:1:in `from_file'

cron("delete_error_log") do
weekday "*"
retry_delay 2
command "\n  sudo find /srv/www/ -name \"error_log\" -delete\n  "
minute "30"
cookbook_name :cron_job
month "*"
retries 0
recipe_name "delete_error_log"
day "*"
action [:create]
user "root"
hour "12"
end
=======================================================
Was it helpful?

Solution

The problem is the multi-line command, which seems to be directly put into the crontab files. Instead, supply the command like this:

cron "delete_error_log" do
  hour "12"
  minute "30"
  command 'sudo find /srv/www/ -name "error_log" -delete'
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top