Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange things when running script via cron

Status
Not open for further replies.

bertieuk

IS-IT--Management
Jun 1, 2004
175
I have a strange problem.
I have written a script that backs up a linux machine. If I run this script from the OS then all seems to be fine.

Put it in a cron job then only 180KB backs up. But funny thing is that this script works ok on redhat and TAO

The code is as follows......(How do I outline code on Tek Tips?)


dateselect() {
case $1
in
"1") DOW=Monday;
SHORTDOW=MON;;
"2") DOW=Tuesday;
SHORTDOW=TUE;;
"3") DOW=Wednesday;
SHORTDOW=WED;;
"4") DOW=Thursday;
SHORTDOW=THU;;
"5") DOW=Friday;
SHORTDOW=FRI;;
"6") DOW=Saturday;
SHORTDOW=SAT;;
"7") DOW=Sunday;
SHORTDOW=SUN;;
esac
}

MYDATE=`date +%u`

dateselect $MYDATE

# Clear the backup directory prior to the copy
rm -f /backup/*

if [ "$DOW" = Wednesday ]
then
cd /
tar -cvzf /backup/auth1.ptstream_FULL_WK1.tgz ./ \
--exclude='./backup' \
--exclude='./dev' \
--exclude='./initrd' \
--exclude='./opt' \
--exclude='./lost+found' \
--exclude='./misc' \
--exclude='./var/lib/mysql' \
--exclude='./var/spool' \
--exclude='./proc' \
--exclude='./floppy' \
--exclude='./lost+found' \
--exclude='./tmp' \
--exclude='./var/powermail' \
--exclude='./var/log' \
--exclude='./cdrom' \
--exclude='./mnt'
else
cd /
tar -cvzf /backup/linux1_Daily_$SHORTDOW.tgz ./home ./root ./etc
fi


Thanks

Si
 
(How do I outline code on Tek Tips?)

write the code inside:
[ code ]
..your code here..
[ /code ]

(with no spaces)

1. try to add "#!/bin/bash" in the first line of your script in order to open an independent bash shell.
2. instead of:
cd /
tar -cvzf /backup/linux1_Daily_$SHORTDOW.tgz ./home ./root ./etc

I should put
tar -cvzf /backup/linux1_Daily_$SHORTDOW.tgz /home /root /etc

Note I erase the . in the ./home ./root and ./etc. The same for WED day.

3. Is your cron running as root or another user?

Cheers.
 
Thank Chacalinc for the reply

I already have "#!/bin/bash" with the script....just missed it out of the above listing.

I thought by using ./home ./root ./etc would allow me to reference a restore from my current path and give me the oppotunity to restore files without the potential danger of overwriting.

I will make the changes to see if there are any differences.

Thanks

Si
 
I have tried changing the references ./home ./root ./etc to /home /root /etc (removing the cd /)

No change.

Also this only seems to be happening on Debian Linux....I have tested on redhat and TAO and they are OK.

Thanks Si
 
No symbolic links not followed by the tar in the Debian box ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I've added -h to tar but I'm still getting the same results.

The full and daily tar backups still produce a file of aprox 181KB......but if run manually the process runs ok.

Si
 
Have you tried a diff between the tar -t lists to discover the missing files ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV

Yea thanks

I had already looked at the archive and it seem to stop within the /home directory.

Si
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top