issue with crontab job execution
Dear Friends
I'm having some issue when executing script via cron the script run fine when i run it manually ./scriptname.sh & takes around 10min but when it executed from cron seems it's not running properly. We have echo like "job starting at " & "job ending at" From the logfile I can see that the echo command is executed but not other commands in between. starting & ending time is same (or 1sec diff) but actually it should take 10min. I'm not able to capture terminal message written by this script. when run manually 'script' command work ( thogh no issue when run manually). I can't include 'script' command in this script as I'm not able to pass ctrl+D/exit to terminate it. The devloper who actually write this script ( with TGIT command) couldn't help me much. (It's a housekeeping job) Could someone please help me to find the possible cause of this ? Is there any way to capture the terminal message in log file when the script run which possibly can help to see errors? ( job run at midnight when no one available at office) NB: when I run manually first time - it initially showing dir not found - though mentioned path inside script was correct. Then I create new .sh script by vi & copy same commands again & then it execute in newly created script without any issue.not sure about the reason. |
Are you using absolute paths for the script name in your cron entry?
|
se michaelk post but also add set -xvv at the top of your script and push the data to a log file so you can see exactly what is going on.
|
Further clarification
$crontab -l 10 01 * * * /scripts/git/repack.sh where cat /scripts/git/repack.sh echo "starting script ... at `date` " >> /scripts/git/log/`date +20%y%m%d`_repack.log cd /home/gitadmlocal/repositories/ILP/CoreProduct.git < git command writed by developer -- which is not doing anything when run from cron> echo "Ending script after running... at `date` " >> /scripts/git/log/`date +20%y%m%d`_repack.log Housekeeping command working when run the script manually ./repack.sh |
Quote:
/home/gitadmlocal/repositories/ILP/CoreProduct.git |
Here is the complete script ( repack.sh)
echo "starting script ... at `date` " >> /scripts/git/log/`date +20%y%m%d`_repack.log cd /home/gitadmlocal/repositories/ILP/CoreProduct.git git repack -a -d -f --window-memory 200m --max-pack-size 200m --depth 50 echo "Ending script after running... at `date` " >> /scripts/git/log/`date +20%y%m%d`_repack.log script run fine when run manually by ./repack.sh |
cron has a very limited path environment which is different then your users. Try using the full path to git.
|
I've mentioned full path to 'git' command in the script now. This is now working.
Many Thanks for your help. |
All times are GMT -5. The time now is 11:31 AM. |