Cron job

Hi All

I am trying to run a .sh file from cron but its not performing its intended purpose, though the same sh file works fine when triggered manually.Following mail I recieve when it tries to run the script.

*********************************************************
To: wlsdev05
Subject: Output from "cron" command
Content-Length: 325

Your "cron" job on mfrkuxwbd01
/opt/bea/wls61/config/devo5/batch_automation/batchPolicy/startBatchPolicy.sh > /opt/bea/wls61/config/devo5/batch_automation/batchPolicy/logs/BatchPolicy.log 2>&1

produced the following output:

sh: /opt/bea/wls61/config/devo5/batch_automation/batchPolicy/logs/BatchPolicy.log: cannot create
*****************************************************
Permissions are also granted

opt/bea/wls61/config/devo5/batch_automation/batchPolicy/startBatchPolicy.sh > /opt/bea/wls61/config/devo5/batch_automation/batchPolicy/logs/BatchPolicy.log 2>&1

remove '2>&1' from cron job entry & try .

regards
abhijeet

Hi Abhijeet

Thanks!!! I did tried with removing '2>&1' from cron job entry. But it did nt worked even then.

Regards
Pankaj

keep it removed though.
can you post your script & complete entry of cron job ?

regards
abhijeet

Hi

Following is the script :

#!/bin/ksh
#
# This Script will Start Policy Verification
###########################################

cd /opt/bea/wls61/config/wlsdev05/batch_automation/batchPolicy

JAVA_HOME=/opt/bea/jdk131
WL_HOME=/opt/bea/wls61
INSTANCE=claimsUAT
FRAMEWORK_LIB=$WL_HOME/config/$INSTANCE/lib/com/fits
SERVICE_HOME=$WL_HOME/config/$INSTANCE/services
BATCH_HOME=$WL_HOME/config/$INSTANCE/batch/lib
CONFIG_HOME=$WL_HOME/config/$INSTANCE/batch/config

CLASSPATH=.:$BATCH_HOME/batch.jar:$BATCH_HOME/classes12.jar:$SERVICE_HOME/plus/lib/com/fits/plus.jar:$SERVICE_HOME/diary/lib/
com/fits/diary.jar:$FRAMEWORK_LIB/FitsUtil.jar:$FRAMEWORK_LIB/FitsFramework.jar:$FRAMEWORK_LIB/jdom.jar:$BATCH_HOME/NetCompon
ents.jar:$FRAMEWORK_LIB/xercesImpl.jar:$FRAMEWORK_LIB/customerService.jar:$SERVICE_HOME/numbering/lib/numberingService.jar:$S
ERVICE_HOME/question/lib/com/fits/QuestionEngine.jar:$WL_HOME/lib/weblogic.jar:$SERVICE_HOME/ios/lib/ios.jar:$BATCH_HOME/Acco
untService.jar:$BATCH_HOME/AddressService.jar:$BATCH_HOME/Producer.jar:$FRAMEWORK_LIB/FITSDBPool.jar

BATCH_LIB=$BATCH_HOME/lib

CLASSPATH=$BATCH_HOME/claims.jar:$BATCH_HOME/mail.jar:$BATCH_HOME/activation.jar:$CLASSPATH

RUNTIME_OPTIONS="-Dconfig.file=$CONFIG_HOME/batch.xml -Duser.timezone=America/New_York -Djava.naming.factory.initial=weblogic
.jndi.T3InitialContextFactory -Djava.naming.provider.url=t3://172.16.18.149:9000 -Djava.naming.security.principal=system -Dja
va.naming.security.credentials=mover03"

mv logs/200* logs/bak
echo $RUNTIME_OPTIONS

$JAVA_HOME/bin/java $RUNTIME_OPTIONS -cp $CLASSPATH com.fits.service.claimservice.batch.policyverification.BatchPolicyVerific
ationMain $1 $2 $3

************************************

And following is the entry in crontab :
*******************************************************
## Testing of Automation for Policy Verification - Pankaj
00 02 * * * /opt/bea/Wls61/config/devo5/batch_automation/batchPolicy/startBatchPolicy.sh > /opt/bea/wls61/config/dev05/batch_automation/batchPolicy/logs/batchPolicy.log
##
***************************************

Note : All permission is granted to sh file.

make sure you have write permissions to
/opt/bea/wls61/config/dev05/batch_automation/batchPolicy/logs directory

also try to source ".profile" of the user (with which the script is to be run)
in the script itself.

for e.g
#! /bin/ksh
cd <user_home_directory or the location where .profile is kept>
. .profile
.
.
remaining script

regards
abhijeet

Hi

It has write permission .

Following is the .profile entry that I can locate:

Path /etc/.profile
***********************************
# The profile that all logins get before using their own .profile.

trap "" 2 3
export LOGNAME PATH

if [ "$TERM" = "" ]
then
if /bin/i386
then
TERM=sun-color
else
TERM=sun
fi
export TERM
fi

# Login and -su shells get /etc/profile services.
# -rsh is given its environment in its .profile.

case "$0" in
-sh | -ksh | -jsh)

    if [ ! -f .hushlogin ]
    then
            /usr/sbin/quota
            \#       Allow the user to break the Message-Of-The-Day only.
            trap "trap '' 2"  2
            /bin/cat -s /etc/motd
            trap "" 2

            /bin/mail -E
            case $? in
            0\)
                    echo "You have new mail."
                    ;;
            2\)
                    echo "You have mail."
                    ;;
            esac
    fi

esac

umask 022
trap 2 3

*************

Now can u guide me how to proceed. I cannot understand ur .profile concept.

Regards
Pankaj

Hi Abhijit

we tried with this :

cd /export/home/wlsdev05
.profile
cd /opt/bea/wls61/config/dev05/batch_automation/batchPolicy

JAVA_HOME=/opt/bea/jdk131
WL_HOME=/opt/bea/wls61
INSTANCE=dev05
FRAMEWORK_LIB=$WL_HOME/config/$INSTANCE/lib/com/fits
SERVICE_HOME=$WL_HOME/config/$INSTANCE/services
BATCH_HOME=$WL_HOME/config/$INSTANCE/batch/lib
CONFIG_HOME=$WL_HOME/config/$INSTANCE/batch/config

CLASSPATH=.:$BATCH_HOME/batch.jar:$BATCH_HOME/classes12.jar:$SERVICE_HOME/plus/lib/com/fits/plus.jar:$SERVICE_HOME/diary/lib/
com/fits/diary.jar:$FRAMEWORK_LIB/FitsUtil.jar:$FRAMEWORK_LIB/FitsFramework.jar:$FRAMEWORK_LIB/jdom.jar:$BATCH_HOME/NetCompon
ents.jar:$FRAMEWORK_LIB/xercesImpl.jar:$FRAMEWORK_LIB/customerService.jar:$SERVICE_HOME/numbering/lib/numberingService.jar:$S
ERVICE_HOME/question/lib/com/fits/QuestionEngine.jar:$WL_HOME/lib/weblogic.jar:$SERVICE_HOME/ios/lib/ios.jar:$BATCH_HOME/Acco
untService.jar:$BATCH_HOME/AddressService.jar:$BATCH_HOME/Producer.jar:$FRAMEWORK_LIB/FITSDBPool.jar

BATCH_LIB=$BATCH_HOME/lib

CLASSPATH=$BATCH_HOME/claims.jar:$BATCH_HOME/mail.jar:$BATCH_HOME/activation.jar:$CLASSPATH

RUNTIME_OPTIONS="-Dconfig.file=$CONFIG_HOME/batch.xml -Duser.timezone=America/New_York -Djava.naming.factory.initial=weblogic
.jndi.T3InitialContextFactory -Djava.naming.provider.url=t3://172.16.18.149:8005 -Djava.naming.security.principal=system -Dja
va.naming.security.credentials=mfxclaims"

mv logs/200* logs/bak
echo $RUNTIME_OPTIONS

$JAVA_HOME/bin/java $RUNTIME_OPTIONS -cp $CLASSPATH com.fits.service.claimservice.batch.policyverification.BatchPolicyVerific
ationMain $1 $2 $3 > logs/batchPolicy.log 2>&1 &

*******************

It created a log file but of zero bit size, which should'nt be.

Please advice

Regards

Pankaj

pankaj,
i am talking of the user with which you are executing the script manually or for which you are using cron jobs.

go to that user's home path & search for a hidden file called " .profile" which sets users individual enviroment.

# ls -la .profile

check if this file is thr & if its thr ,just do what i wrote in last post.

/etc/profile is common for all users & is called first before executing users individual .profile.

normally every user on a system will have its own .profile.

btw,when u run this script manually ,does it generate log file & gives you the desired o/p?

regards
abhijeet

Hi Abhijit

I did exactly what you did as described in my last post. It also created a log with zero bit ( which ideally it should not ).

Also when I run the script ( without embedding .profile in the script ) manually it gives desired output.

Please guide me

Thanks

Pankaj

pankaj
i can't see any echo or print statements in your script.
what o/p you expect in the log file??

just check your desired o/p has come.

abhijeet

Hi Abhijeet

If you see the script it will tell you that all the output/error will get redirected to log file , that is why we are using '>' symbol.

Also we have one echo statement at the end of our main script ie

echo $RUNTIME_OPTIONS.

I will appreciate if you kindly share your contact no so that I may call you up, explaining the things in details.

Regards
Pankaj

echo $RUNTIME_OPTIONS

$JAVA_HOME/bin/java $RUNTIME_OPTIONS -cp $CLASSPATH com.fits.service.claimservice.batch.policyverification.BatchPolicyVerific
ationMain $1 $2 $3 > logs/batchPolicy.log 2>&1 &

ok do thesethings

1.remove that '&' from your script.
2.instaed of '2>&1' ,put '2>> (some error file path)' & check what error is coming while executing the script.

lastly. " echo $RUNTIME_OPTIONS " statement is NOT redirected ..this won't come in the log file.....right?

let me know

regards
abhijeet

Hi Abhijit

Following is the error after modification as per your suggestion.

Your "cron" job on mfrkuxwbd01
/opt/bea/Wls61/config/devo5/batch_automation/batchPolicy/startBatchPolicy.sh > /opt/bea/wls61/config/dev05/batch_automation/batchPolicy/logs/batchPolicy.log

produced the following output:

sh: /opt/bea/Wls61/config/devo5/batch_automation/batchPolicy/startBatchPolicy.sh: not found

****************************

Script:
#!/bin/ksh
#
# This Script will Start Policy Verification
###########################################

PATH=$PATH:/export/home/wlsdev0
cd /opt/bea/wls61/config/dev05/batch_automation/batchPolicy

JAVA_HOME=/opt/bea/jdk131
WL_HOME=/opt/bea/wls61
INSTANCE=dev05
FRAMEWORK_LIB=$WL_HOME/config/$INSTANCE/lib/com/fits
SERVICE_HOME=$WL_HOME/config/$INSTANCE/services
BATCH_HOME=$WL_HOME/config/$INSTANCE/batch_automation/lib
CONFIG_HOME=$WL_HOME/config/$INSTANCE/batch_automation/config

CLASSPATH=.:$BATCH_HOME/batch.jar:$BATCH_HOME/classes12.jar:$SERVICE_HOME/plus/lib/com/fits/plus.jar:$SERVICE_HOME/diary/lib/
com/fits/diary.jar:$FRAMEWORK_LIB/FitsUtil.jar:$FRAMEWORK_LIB/FitsFramework.jar:$FRAMEWORK_LIB/jdom.jar:$BATCH_HOME/NetCompon
ents.jar:$FRAMEWORK_LIB/xercesImpl.jar:$FRAMEWORK_LIB/customerService.jar:$SERVICE_HOME/numbering/lib/numberingService.jar:$S
ERVICE_HOME/question/lib/com/fits/QuestionEngine.jar:$WL_HOME/lib/weblogic.jar:$SERVICE_HOME/ios/lib/ios.jar:$BATCH_HOME/Acco
untService.jar:$BATCH_HOME/AddressService.jar:$BATCH_HOME/Producer.jar:$FRAMEWORK_LIB/FITSDBPool.jar

BATCH_LIB=$BATCH_HOME/lib

CLASSPATH=$BATCH_HOME/claims.jar:$BATCH_HOME/mail.jar:$BATCH_HOME/activation.jar:$CLASSPATH

RUNTIME_OPTIONS="-Dconfig.file=$CONFIG_HOME/batch.xml -Duser.timezone=America/New_York -Djava.naming.factory.initial=weblogic
.jndi.T3InitialContextFactory -Djava.naming.provider.url=t3://172.16.18.149:8005 -Djava.naming.security.principal=system -Dja
va.naming.security.credentials=mfxclaims"

mv logs/200* logs/bak
echo $RUNTIME_OPTIONS

$JAVA_HOME/bin/java $RUNTIME_OPTIONS -cp $CLASSPATH com.fits.service.claimservice.batch.policyverification.BatchPolicyVerific
ationMain $1 $2 $3 > logs/batchPolicy.log 2>> /opt/bea/wls61/config/dev05/batch_automation/batchPolicy/logs/batcherr.log.

*******************

Crontab entry is :

## Testing of Automation for Policy Verification - Pankaj
13 00 * * * /opt/bea/Wls61/config/devo5/batch_automation/batchPolicy/startBatchPolicy.sh > /opt/bea/wls61/config/dev05/batch_automation/batchPolicy/logs/batchPolicy.log
##

Please suggest

Regards
Pankaj

sh: /opt/bea/Wls61/config/devo5/batch_automation/batchPolicy/startBatchPolicy.sh: not found

have this sh being moved or renamed??

post the contents of log & error file

regards
abhijeet

Hi Abhijit

sh: /opt/bea/Wls61/config/devo5/batch_automation/batchPolicy/startBatchPolicy.sh: not found

No !!!! This script has neither been moved nor being renamed.

log file was created as blank and there was no error file created.

What I think is that we are missing somewhere in path settings. Just a guess.

Regards
Pankaj

Hi All ,

We have few scripts which uses common environment/path setting variables.
Now instead of putting classpath , framework,java_home ..... etc. in all the script, can we make a file with all common settings which can be envoked by the scripts while running. If yes , say setting file is setEnv.sh, how will we envoke it in script, so that it automatically sets all the env/path.

Thanks in advance for your suggestion.

Regards

Pankaj