anomalous behaviour when I execute the script via cron


 
Thread Tools Search this Thread
Operating Systems Solaris anomalous behaviour when I execute the script via cron
# 1  
Old 09-23-2009
anomalous behaviour when I execute the script via cron

Hi ,
I am having a strange problem with my cron job :

here is the script that I am scheduling from cron

WrapperScript.ksh
Code:
#!/bin/ksh
########## Global Variables ##########
DATE=$(date +"%b-%d-%y")
TIME=$(date +"%H:%M")
LOGFILE=sonar_execution_$DATE.log
########## Main Processing ###########
. /export/home/cmbuild/sonar-script/kickstartSonar.ksh >> /export/home/cmbuild/sonar-script/log/$LOGFILE  2>&1

The script is working perfectly fine while I am executing the Wrapperscript.ksh manually , which in turn calls kickstartSonar.ksh



kickstartSonar.ksh
Code:
#!/bin/ksh
#Setting path for Maven
echo Setting Maven environment...
. /export/home/cmbuild/.profile
PATH=/export/home/cmbuild/apache-maven-2.2.1/bin:$PATH ;export PATH

echo `/usr/ucb/whoami`

########## Global Variables ##########
DATE=$(date +"%b-%d-%y")
TIME=$(date +"%H:%M")
LOGDIR=/export/home/cmbuild/sonar-script/log
LOGFILE=/export/home/cmbuild/sonar-script/log/sonar_execution_$DATE.log
CCM_START_DIR=/export/home/cmbuild/qdrive/use
EXEC_DIR=/export/home/cmbuild/sonar-script
########## Log File Function ###########
log_it()
{
message="$DATE $TIME $@"
echo $message
echo $message >>$LOGFILE 2>&1
}

########## Main Processing ###########

find $LOGDIR -name \*.log -mtime +2 -type f -exec rm -rf {} \;

pwd

cd $CCM_START_DIR

pwd

. ccmstart

cd $EXEC_DIR



while IFS=":" read f1 f2

do

release_target=$(echo $f1|sed 's/-/\//g')
echo ${release_target}

build_version=`ccm query -type project -name $f2 -state prep -u -format %version "release='${release_target}'"`


echo --------------------------------------------------------------------- 
echo  Kicking Sonar Analysis for subproject $f2 in $f1    
echo ---------------------------------------------------------------------


build_version=${build_version## }
build_version=${build_version%% }
echo  "Build version is ${build_version}"
artifact_version=`echo $build_version | cut -d'-' -f2`
echo  "artifact_version is ${artifact_version}"

cd /u01/data/cmbuild/ccm_wa/prep-work-area-${f1}/${f2}

pwd

if [ -s pom.xml ]; then

pwd

mvn  sonar:sonar  -Dglobal-version=${build_version}  -Dartifact-version=${artifact_version}

else
log_it pom.xml does not exist for project $f2 
fi
done < /export/home/cmbuild/sonar-script/applicationlist.properties

ccm stop

but while running via cron it is not able to get the synergy session (. ccmstart) .I assume it could be because I am using korn shell in the script while cron is using the born shell, but then I am not able to come up with the solution,any pointers regarding this problem will be much appreciated.

PS:I am fairly new to shell scripting
Quote:
I have used period '.' before executing any subscript to make an inline execution

Last edited by alookachaloo; 09-23-2009 at 03:08 PM..
# 2  
Old 09-23-2009
I haven't carefully read your entire script, but problems like this are almost always due to the fact that cron jobs run with NO user profile, not even root. If there are some paths, environment variables, etc. in your profile when you run it manually which are not copied into the script that can cause the failure.
# 3  
Old 09-24-2009
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need assistance to define path on a script which cron will execute

I have written a script to execute some sql statement via executable file. It is working fine via command line, however when I schedule it in cron. The executable file is looking for library file in its root directory. Wonder where does cron run the script from, and can we get the script... (4 Replies)
Discussion started by: jaapar
4 Replies

2. Solaris

cannot execute sqlplus in shell script under cron

Hi, I have a bourne shell script that needs to login into sqlplus and execute a stored procedure. I need this shell script to be run under a user crontab. It works fine if run under normal shell prompt. But it gave error message in my log file when run under crontab: SQL*Plus: Release... (4 Replies)
Discussion started by: joe_x
4 Replies

3. Shell Programming and Scripting

Difference between using shell or cron to execute a script

Hi! Maybe i am here in the wrong section for the problem, but let me try to explain. I have the following simple backup script, as a solution till the final backup solution is online. Unfortunatly it will only work when executed manually. When i set up a cron job to execute the script, only the... (4 Replies)
Discussion started by: locutus01
4 Replies

4. UNIX for Dummies Questions & Answers

cron used to execute multiple commands

have to run multiple commands at a specified time by the user... (3 Replies)
Discussion started by: hemaa
3 Replies

5. Shell Programming and Scripting

cron does not execute script properly

I have a simple script that checks for certain printers and records them to a file. When I run the script manually at the command prompt, it works perfect, but when I run the script via cron, nothing happens. No errors reported, and no records are written out. I'm using Solaris 10. Below is the... (4 Replies)
Discussion started by: lmatlebyane
4 Replies

6. UNIX for Dummies Questions & Answers

a cron job needs a perl script to execute

Hello evreyone, this is my first post, and to say i'm new to this is an understatement. I know very little about perl scripts and hope some one can help me. i'm looking to get a script that a cron job can execute. what the script needs to to is 1) connect to a mysql database 2) go to a... (2 Replies)
Discussion started by: Exader
2 Replies

7. UNIX for Dummies Questions & Answers

CRON job to execute all scripts in a directory

Hi everyone: I'm trying to make a CRON job that will execute Fridays at 7am. I have the following: * 7 * * 5 I've been studying up on CRON and I know to have this in a file and then "crontab filename.txt" to add it to the CRON job list. The CRON part I believe I understand, but I would... (6 Replies)
Discussion started by: Annorax
6 Replies

8. Shell Programming and Scripting

script execute by cron problem, but manual ok

Hi; I'm facing the problem with my script like below 30 0 * * * /data/SCRIPT/LOADLOGS/loadata1.sh 2 1 >> /tmp/loaddata.txt loadata1.sh calling a another 2 scripts which we need to exe in sequence. when it perform by cron jon, sometimes it just can process 20 recs or less or nothing but... (6 Replies)
Discussion started by: izai
6 Replies

9. UNIX for Dummies Questions & Answers

Cron job -- to execute at every first Sunday of every month

Dear all How can I schedule the cronjob to be run sometime at every first Sunday at every month? I have the edit the cronjob every month now, thanks (2 Replies)
Discussion started by: shanemcmahon
2 Replies
Login or Register to Ask a Question