Nested loop not running using cronjob


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Nested loop not running using cronjob
# 1  
Old 09-21-2007
Question Nested loop not running using cronjob

Hi

I have created a shell script which uses three nested loops. When the cronjob is running the script there is a for loop which call a function which has two nested for loops. It is going into the function but the for loop in the function is not running. Can someone pleasae give me a solution for this. I have tried and removed the function also. Even with this the second for loop is not running.

You can find the shell script below:

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

#!/bin/ksh
#--------------- Make a file Broker.dat with all the Broker Names -----------
mqsilist |grep Broker |awk '{print substr($3,0,8)}' > /amp/home/mqsi/scripts/Broker.dat

function check_msg_flow {
BRKNAME=$1

for exec in `mqsilist $BRKNAME |awk '{print substr($4,0,8)}' |grep -v "completi"`
do
execgr=`expr $execgr + 1`
#------------ Check whether the execution group is in debug mode ------------

temp=`mqsireporttrace $BRKNAME -u -e $exec |grep -v "BIP8071I:" |awk '{print substr($4,0,5)}'`
if [[ $temp = debug ]]; then
printf "%-45s %-25s %-20s\n" "-" $exec $BRKNAME >>MessageFlows.txt
mqsichangetrace $BRKNAME -u -e $exec -l none -r
fi

#--------- Check whether the message flow under a perticular broker and execution group is in debug mode -----------
for flow in `mqsilist $BRKNAME -e $exec |awk '{print substr($3,0,50)}' |grep -v "command"`
do
flows=`expr $flows + 1`
flag=`mqsireporttrace $BRKNAME -u -e $exec -f $flow |grep -v "BIP8071I:" |awk '{print substr($4,0,5)}'`

if [[ $flag = debug ]]; then

mqsichangetrace $BRKNAME -u -e $exec -f $flow -l none -r
printf "%-45s %-25s %-20s\n" $flow $exec $BRKNAME >>MessageFlows.txt
fi
done
done
}

flows=0
execgr=0
Brkrs=0

mailids="abc@abc.com"

echo "\t \t TRACE LEVEL HAS BEEN TURNED OFF FOR THE FOLLOWING COMPONENTS" >MessageFlows.txt

echo "*************************************************************************************************** *************">>MessageFlows.txt
printf "%-45s %-25s %-20s\n" "MESSAGE FLOW NAME" "EXECUTION GROUP" "BROKER NAME" >>MessageFlows.txt
echo "*************************************************************************************************** *************" >>MessageFlows.txt

for brokers in `dspmq | grep Ru |awk '{print substr($1,8,8)}'`
do
echo "Checking the messages flows under the broker $brokers"
check_msg_flow $brokers
Brkrs=`expr $Brkrs + 1`
done

mailx -s "WMQI TRACE LEVEL REPORT for `hostname` - CHECKED $Brkrs BROKERS : $execgr EXECUTION GROUPS : $flows MESSAGE FLOWS" $mailids <MessageFlows.txt
# 2  
Old 09-21-2007
As a wild guess - the job is being run as Bourne shell which has problems with what you are doing. By default /bin/sh is the shell used by cron jobs. Yes, I do see a shebang to ksh. But still. I don't know for sure.
# 3  
Old 09-25-2007
when i running this script directly its working fine..but only when its get executed by a croj job then only the nested for loops problem is occuring can anybody help me out..I tried everything i could but not able to find a solution
# 4  
Old 09-25-2007
Quote:
Originally Posted by bihani4u
when i running this script directly its working fine..but only when its get executed by a croj job then only the nested for loops problem is occuring can anybody help me out..I tried everything i could but not able to find a solution
I had problems running crontabs until I added absolute paths to my file references used in the script. Search for "crontab" or similar entries in previous postings on this forum.
# 5  
Old 09-25-2007
my cron job is running. But the problem is that is going in the first loop but not going in the loop after that.
I have enterd this command in crontab



15 * * * * /amp/home/mqsi/scripts/ChkAllMsgFlowForDebug.sh >/amp/home/mqsi/scripts/ChkAllMsgFlowForDebug.txt&

if u see in the scripts that i am storing output in file MessageFlows.txt and
Broker.dat files but the messageflows.txt file is not updating at all and Broker.dat file is updating but nothing is coming in it

content of Broker.dat file when i run script directly.

INVTXT01
BSTART01
GBMBXT01
IUXXXT01
USRXXT01
USRXXT03
USRXXT05
USRXXT07
EXTRNT01
SDSXXT01
and its coming empty when script is getting run by cronjob and messageflows.txt is not updating at all.

Its taking around 10 mins when i execute it directly but using cronjobs its getting over in seconds because its not going in nested loops.



Please help me in this thing. i am trying from around 5 days but nothing found on this thing.

Thanks in advance.

Last edited by bihani4u; 09-25-2007 at 12:02 PM..
# 6  
Old 09-25-2007
Quote:
Originally Posted by bihani4u
my cron job is running. But the problem is that is going in the first loop but not going in the loop after that.
I have enterd this command in crontab



15 * * * * /amp/home/mqsi/scripts/ChkAllMsgFlowForDebug.sh >/amp/home/mqsi/scripts/ChkAllMsgFlowForDebug.txt&

if u see in the scripts that i am storing output in file MessageFlows.txt and
Broker.dat files but the messageflows.txt file is not updating at all and Broker.dat file is updating but nothing is coming in it

content of Broker.dat file when i run script directly.

INVTXT01
BSTART01
GBMBXT01
IUXXXT01
USRXXT01
USRXXT03
USRXXT05
USRXXT07
EXTRNT01
SDSXXT01
and its coming empty when script is getting run by cronjob and messageflows.txt is not updating at all.

Its taking around 10 mins when i execute it directly but using cronjobs its getting over in seconds because its not going in nested loops.



Please help me in this thing. i am trying from around 5 days but nothing found on this thing.

Thanks in advance.
As I said I had the same problem and solved it using full path on every file-reference. The crontab-job will start but it will not perform all it should. Search here and you will see that many have had the same problem. Of course I can not guarantee this is the problem in your case, but it is a repeating problem for many.
# 7  
Old 09-25-2007
I've had the same issues with running a job manually and running it from the cron. I've found environment variables used can be different between the scheduler and a manual log into the server. Do you have the cron log stdout for the job?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Cronjob not running on Ubuntu 14.04

I have created a test cronjob using crontab -e that runs a script at /home/cmccabe/cron.sh. I am not sure the script doesn't run though I can call it in terminal. Thank you :). crontab -e (run script sat at 6:10pm)? 10 18 * * 6 /home/cmccabe/cron.sh contents of cron.sh #!/bin/bash... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. Shell Programming and Scripting

My Cronjob is not running

I created a script, size=`du -sm` size=`echo $size | sed 's/.$//'` size1='30720' if then { find /ask/tarballs -type f -name "*.tgz" -mtime +30 -exec ls -l {} \; find /ask/tarballs -type f -name "*.tgz" -mtime +30 -exec rm -f {} \; } else echo "Directory size doesnt exceed Threshold... (12 Replies)
Discussion started by: shaal89
12 Replies

3. Shell Programming and Scripting

Nested if loop

Hi Team, I just want to check whether my nested if loop used is correct or not. if ] if ] export1 else export2 fi else if ] export3 else export4 fi fi Thanks Shiva (5 Replies)
Discussion started by: shivashankar_S
5 Replies

4. UNIX for Dummies Questions & Answers

Script not running through Cronjob

Hi, I have a .ksh script which updates the database. The script is running fine manually but it is not running through cron.All the file permissions are fine. The script contents are as below: #!/usr/bin/ksh ddate=`date +%Y%m%d` echo $ddate nohup sqlplus crm/crm @db_state_sync.sql >>... (3 Replies)
Discussion started by: shivangi
3 Replies

5. Shell Programming and Scripting

Cronjob not running

Hi, having problem running my cronjob, need the script to run every monday. And the error i'm getting is "No such file or directory", i've tried to change the env to /bin/bash and also /usr/bin/sh but both failed. Need help here. tq 0 0 * * 1 /bin/bash /home/omc/munir/raccli_rnc.sh Rgds... (3 Replies)
Discussion started by: adawiyah29
3 Replies

6. UNIX for Dummies Questions & Answers

how to cancel a cronjob if the cronjob still running

hi everyone I'm newbie in this forum hope I can get some help here :) I have a command in crontab that executed every 1 minute sometime this command need more than 1 minute to finish the problem is, the crontab execute this command although it's not finish processing yet and causing the system... (7 Replies)
Discussion started by: 2j4h
7 Replies

7. UNIX for Advanced & Expert Users

SYS CRONJOB just not running...

I'm trying to run "SAR -i 60" under #/var/spool/cron/crontabs/SYS 0,10,20,30,40,50 0-6 sh -c "/usr/lib/sa/sa1 60 10 &" 55 23 * 0-6 /usr/lib/sa/sa2 -i 900 -A machine is not running above cron job under "sys" at all. This suppose to run every minutes and all time in 24 hours. When day... (6 Replies)
Discussion started by: deal732
6 Replies

8. Shell Programming and Scripting

Running scripts through cronjob.

Hello everybody, I'm trying to run a shell script in crontab file. But anyhow it's not getting executed. Following is the command that I've used in crontab. 30 07 * * * . ./.cronprofile;/om/reports/reportscripts/jitu/prod/prd_pre_to_post.sh 35 11 * * * .... (3 Replies)
Discussion started by: jitu.jk
3 Replies

9. UNIX for Advanced & Expert Users

Cronjob is not running

hi, I have a shell script which has a sql plus code and unix if else condition. The file is located at root.I logged in as a root user and i have all permissions. I tried to set up a cron job so that the script need to run every minute.the script is running successfully without any problem. I... (2 Replies)
Discussion started by: sanei05
2 Replies
Login or Register to Ask a Question