Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've recently updated Trac from 0.11.4 to 0.12.2. I'm using the following shell script to backup Trac installation:

#!/bin/sh
DIR=/root/backup/trac/
NAME=`date +%Y-%m-%d-%H-%M`
cd $DIR
trac-admin /var/trac/projects/myproject/ hotcopy ./temp
tar -zcf TRAC_$NAME.tar.gz -C $DIR/temp .
rm -rf ./temp

It works ok when run from console, but the cronjob fails with following message:

Traceback (most recent call last):
 File "/usr/bin/trac-admin", line 5, in <module>
   from pkg_resources import load_entry_point
 File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 2675, in <module>
   parse_requirements(__requires__), Environment()
 File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 552, in resolve
   raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: Trac==0.11.4
tar: /root/backup/trac//temp: Cannot chdir: No such file or directory
tar: Error is not recoverable: exiting now

Why does it work when run manually and not when from crontab? Why does it look for 0.11.4 version of Trac if I use 0.12.2 now?

Trac was installed and upgraded with easy_install.

share|improve this question
1  
It is recommended to use full paths in cron jobs. Otherwise, you may end up calling the wrong script or program. Also, you need to make sure that you are executing your script under the same user. –  Khaled Jan 6 '12 at 13:33
    
Thank you very much, that actually solved my problem. I've been using /usr/bin/trac-admin instead of /usr/local/bin/trac-admin all the time :( –  Gepard Jan 6 '12 at 13:57
    
I posted it as answer. You can accept it so that others can benefit from this port. –  Khaled Jan 6 '12 at 14:24
    
Additionally, you are getting an error for an invalid destination. Prior to the trac-admin call you should have some error handing to create the destination if needed. if [ ! -d ./temp ]; then mkdir -p ./temp; fi This looks like Hell with the formatting lost but hopefully you get my point. –  Aaron Copley Jan 6 '12 at 14:55

1 Answer 1

up vote 2 down vote accepted

It is recommended to use full paths in cron jobs. Otherwise, you may end up calling the wrong script or program.

Also, you need to make sure that you are executing your script under the same user.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.