public
Description: Provides clean ruby syntax for defining messy cron jobs and running them Whenever.
Home | Edit | New

Output redirection (logging your cron jobs)

In your schedule.rb file you can specify the redirection options for your commands at a global or command level by setting the 'output' variable.
  # adds ">> /path/to/file.log 2>&1" to all commands
  set :output, '/path/to/file.log'
Or you can STDOUT and STDERR separately,
  # adds ">> cron.log 2> error.log" to all commands
  set :output, {:error => 'error.log', :standard => 'cron.log'}
  
  # adds ">> cron.log" to all commands
  set :output, {:standard => 'cron.log'}
  
  # adds "2> error.log" to all commands
  set :output, {:error => 'error.log'}
Additionally you can set these values at the command level,
  every 3.hours do
    runner "MyModel.some_process", :output => 'cron.log'     
    rake "my:rake:task", :output => {:error => 'error.log', :standard => 'cron.log'}
    command "/usr/bin/cmd"
  end  
In all cases you can if you explicitly set the value of any output to 'nil' it will add a redirect to /dev/null
  # adds ">> /dev/null 2>&1" to all commands
  set :output, nil
  set :output, {:error => nil, :standard => nil}

  # adds ">> /dev/null" to all commands
  set :output, {:standard => nil}

  # adds "2> /dev/null" to all commands
  set :output, {:error => nil}
Last edited by dvrensk, Mon Oct 26 04:52:23 -0700 2009
Home | Edit | New
Versions: