Archive

Posts Tagged ‘crontab’

Crontab script for Ruby on Rails (RoR)

February 25th, 2009 Arthur Gressick No comments

Recently I had to figure out a way to get RoR scripts to run from nightly crontab scripts, it took me a little while to get it working but here is the script that we ended up using to get it working. Results may very and of course if you have problems remember that permissions are usually the first place to look, then look at the path of both the folder and using “which” to make sure cron can get to the program/application.

0 9 * * 1 cd /path/to/application_root/current/ && /usr/bin/rake email:excel RAILS_ENV=production

This will run at 12:09 on Monday each week. It is running from the current directory so that we can always have the latest version of code. Have fun and note this is on Ubuntu linux.

Editing Crontab with nano instead of vi

February 25th, 2009 Arthur Gressick 1 comment

I know that all of the vi people are going to blast me for this but I like nano much better for quick and dirty editing. So when it comes to editing the crontab here is a quick way to change the terminal editor.

EDITOR=nano crontab -e

You should be able to substitute any editor in the place of NANO, Mac OS X has PICO which I think is the same as nano.

Crontab script for Rsync

February 25th, 2009 Arthur Gressick No comments

What is you could run a single script each night automatically and have the files from one server automatically copy to another for backup. Most people use a third party application for this or have copy scripts.

The point of this Rsync script is to sync the files that have changed so that we don’t make more work then is needed. This will compare the files from the source to the target then once if finds the files that need to be copied it will compress the files and then copy them to the destination server. I set up the script to run on a regular basis.

0 3 * * * rsync -avz --password-file=/password_file /path/to/folder/ USER@server.com::path/to/folder/

This will run every midnight at 12:03AM, archive mode + compress, use a password file, syncing source folder with destination folder with username.

Look for the directions on how to setup a rsync server. Also note that this should work fine on Mac OS X but I have not fully tested it on the OS.