Setting up a cron job as user fred
First, I'll set up a little diddy to test my script and make sure crontab is working.
For quick testing, I tell cron to run it every minute and that will be changed for my real backup cron.
For example:
Code:
#!/bin/bash
filename=`date '+%H%M'`
ls /home/images > ~/$filename.txt
Next, I make the script executeable
chmod +x /home/fred/backup.job
I use the vi editor
export EDITOR=vi
Use this command to set the crontab file as being /etc/crontab
crontab /etc/crontab
Edit the crontab to include your script. You could also put the script in one of the /etc/cron folders
crontab -e
Code:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
* * * * * /home/fred/backup.job
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
You need to restart the crond service as root user
Code:
su - -c "service crond restart"
After you have that working properly, you could change the backup script to something more usefull.
For example:
Code:
#!/bin/bash
filename=`date '+%m%d%y'`
cd /home/images
/bin/tar -cvzf /mnt/backup/${filename}.tar.gz . \
> /mnt/backup/${filename}.log \
2> /mnt/backup/${filename}err.log
And the cron could be a reasonable once a day setting.
Add a line to your personal crontab.....
00 23 * * * /mnt/backup/backup.job
Don't forget that root needs to restart the crond.