Creating crontab via Capistrano instead of using crontab -e

I would like to include cron tasks in my Capistrano deployment files, rather than using the following command to manually edit the crontab file:

crontab -e [username] 

Is there a script that I could use in the Capistrano launch command to set the contents of crontab?

+6
ruby cron crontab capistrano
source share
5 answers

In my linux box

 crontab -u userName -l > fileName 

lists the crontab file for the username in fileName.

Then I would use a ruby ​​(or other language) script to update the file.

Finally, I would use

 crontab -u userName fileName 

to update crontab for username

+5
source share

Take a look Whenever gem - it can go beyond what you intend to do, but it uses very simple (Ruby) and makes it easy to install cron jobs in deploying capistrano script.

+15
source share

given that you have a set of variables: new_user

and what do you use use_sudo true

 desc "install crontab" task :install_crontab do run "echo '0 23 * * * /home/#{new_user}/scripts/backup_#{new_user}.sh' | #{sudo} crontab -u #{new_user} -" end 
+4
source share
 def crontab_add(line) config = capture(%Q{crontab -l}).split "\n" return if config.include? line run %Q{(crontab -l; echo "#{line}") | crontab -} end 
+4
source share

Why not include crontab, which can be installed in / etc / cron.d?

0
source share

All Articles