Results 1 to 3 of 3
Hey guys, I have a script that I have built for backing up important data on a server. This script ran fine for a few months then stopped working. Cron ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 02-18-2011 #1
Bash script fails when Cron runs it.
Hey guys, I have a script that I have built for backing up important data on a server. This script ran fine for a few months then stopped working. Cron would run the script fine and the associated files and directories would be created but it's like each command would fail half way through.
When I run this script manually, everything is fine. But when Cron runs it, it fails. Any ideas?
Crontab:
root@titan:~# crontab -l
# m h dom mon dow command
0 21 * * * bash /media/TBU/backups/backup.sh #Daily Backup Script
Script permissions:
-rwxrwxrwx 1 root root 2.6K 2011-02-14 09:05 backup.sh
Script contents:
TM="`eval date +%m-%d-%Y`"
#TM="01-26-2011"
L1="sdb1"
#sleep 10
#sudo killall VBoxHeadless
#3 DAYS-----------------------------------------------------------------------------------------
#sudo mv -f /media/TBU/backups/dates/3 /media/TBU/backups/dates/4
#sudo mv -f /media/TBU/backups/dates/2 /media/TBU/backups/dates/3
#sudo mv -f /media/TBU/backups/dates/1 /media/TBU/backups/dates/2
#sudo touch /media/TBU/backups/dates/1
#echo "sudo rm -rf /media/TBU/backups/`eval date +%m-%d-%Y`" >> /media/TBU/backups/dates/1
#sudo bash /media/TBU/backups/dates/4
#---------------------------------------------------------------------------------------------------
#DOXYGEN-------------------------------------------------------------------------------------
sudo bash /home/prioria/Documents/scripts/doxy/vidtrack.sh
sudo bash /home/prioria/Documents/scripts/doxy/jms.sh
sudo bash /home/prioria/Documents/scripts/doxy/eng.sh
#---------------------------------------------------------------------------------------------------
#SUBVERSION---------------------------------------------------------------------------------
sudo mkdir /media/TBU/backups/$TM
sudo mkdir /media/TBU/backups/$TM/svn
sudo svnadmin dump /mnt/sdb1/svn/repos/eng > /media/TBU/backups/$TM/svn/eng.dump
sudo svnadmin dump /mnt/sdb1/svn/repos/jms > /media/TBU/backups/$TM/svn/jms.dump
sudo svnadmin dump /mnt/sdb1/svn/repos/corp > /media/TBU/backups/$TM/svn/corp.dump
sudo svnadmin dump /mnt/sdb1/svn/repos/it > /media/TBU/backups/$TM/svn/it.dump
#---------------------------------------------------------------------------------------------------
#WIKI---------------------------------------------------------------------------------------------
sudo mkdir /media/TBU/backups/$TM/wiki
sudo cp /mnt/sdb1/vm/MindTouch_Deki_Wiki_itasca_1.9.0a_vm.vmdk /media/TBU/backups/$TM/wiki
#---------------------------------------------------------------------------------------------------
#TRAC-------------------------------------------------------------------------------------------
sudo mkdir /media/TBU/backups/$TM/trac
sudo trac-admin /mnt/sdb1/trac/eng hotcopy /media/TBU/backups/$TM/trac/eng.dump
sudo trac-admin /mnt/sdb1/trac/jms hotcopy /media/TBU/backups/$TM/trac/jms.dump
#---------------------------------------------------------------------------------------------------
#BARRACUDA----------------------------------------------------------------------------------
sudo rm -rf /mnt/sdc1/backup/current
sudo cp -rf /media/TBU/backups/$TM /mnt/sdc1/backup/current
#---------------------------------------------------------------------------------------------------
#sudo VBoxHeadless -startvm wiki
Any help would be greatly appreciated!
-Ryan
EDIT:
Example of problem-
When I manually run the script, everything runs fine and this is the end result of the "Subversion" directory:
-rwxr-xr-x 1 root root 9.6G 2011-02-18 10:38 corp.dump
-rwxr-xr-x 1 root root 46G 2011-02-18 11:03 eng.dump
-rwxr-xr-x 1 root root 62M 2011-02-18 11:03 it.dump
-rwxr-xr-x 1 root root 1.2G 2011-02-18 11:03 jms.dump
However, when Cron runs the script as scheduled, this is the end result:
-rwxrwxrwx 1 root root 195 2011-02-17 11:09 corp.dump
-rwxrwxrwx 1 root root 259M 2011-02-17 11:09 eng.dump
-rwxrwxrwx 1 root root 195 2011-02-17 11:09 it.dump
-rwxrwxrwx 1 root root 195 2011-02-17 11:09 jms.dump
It's like the script is creating the files than giving up on transferring the data.
- 02-18-2011 #2
The Cron daemon has a different command path from root. Try using full path names for your commands. This worked for me when I had cron trouble.
"I'm just a little old lady; don't try to dazzle me with jargon!"
- 02-18-2011 #3
Every command does have a full path, other than the date variable but that's tested to work. The files are being created in the correct paths, they just aren't complete...


Reply With Quote
