Friday, September 28, 2007

Cron job in Linux

Tonight a wrote a one-line shell script to copy my GNUcash files from venus to longstreet everynight. The script is as follows:

scp /admin/"Gnucash files"/*.* root@192.168.47.3:/admin/GNUcash

Translated into English it means:

Securely copy all the files in /admin/"Gnucash files" on my linux server named venus to /admin/GNUcash on my linux server named longstreet.

GNUcash is a financial program like Quickbooks, but it's not near as slick as Quickbooks. But the price is good :) For this script to work, I had to generate a public key for root on venus and then copy it over to the /root/.ssh/authorized_keys file on longstreet. If I had not generated the public key, then every time I ran the script, it would stop and ask for a password. I want this baby to run unattended at night, so there's not going to be any entering-of-passwords.

Then I had to add the script to the cron table on venus using:

crontab -e

and then typing in the name of the script which is /admin/GNUcash-to-longstreet.

It works great. Another step up the admin ladder.....

I know I'm not really supposed to be doing this as root, but it was just a learning experience. Once I know it's working every night, I'll change it to run as some user like "Backup guy" or something like that. Maybe....

1 comment:

jsled said...

Note that for full fidelity, you also will want to copy the equivalent of ${HOME}/.gnucash/, which contains book meta-data and open-/saved-reports.

Ideally, one would also synchronize ${HOME}/.gconf/, which has gconf-managed settings, but that's a bit harder.