LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   issue with crontab job execution (https://www.linuxquestions.org/questions/linux-server-73/issue-with-crontab-job-execution-4175502029/)

INDy2k 04-17-2014 04:02 AM

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.

michaelk 04-18-2014 12:46 PM

Are you using absolute paths for the script name in your cron entry?

lleb 04-19-2014 12:23 PM

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.

INDy2k 04-22-2014 10:13 AM

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

michaelk 04-22-2014 09:02 PM

Quote:

cd /home/gitadmlocal/repositories/ILP/CoreProduct.git
Are you trying to run a command or change directories? If the first then remove the cd.

/home/gitadmlocal/repositories/ILP/CoreProduct.git

INDy2k 04-23-2014 03:53 AM

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

michaelk 04-23-2014 06:28 AM

cron has a very limited path environment which is different then your users. Try using the full path to git.

INDy2k 04-24-2014 01:38 AM

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.