The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
comparing 2 files using nested for loop vadharah Shell Programming and Scripting 0 03-01-2008 04:32 AM
Variable in While Loop Nested If geass Shell Programming and Scripting 6 03-26-2007 06:09 PM
Nested Loop to Echo Multiple Arrays yongho Shell Programming and Scripting 1 07-12-2005 11:35 AM
Nested while read line loop Rakker Shell Programming and Scripting 7 06-24-2005 07:42 AM
nested loop chinog Shell Programming and Scripting 5 04-20-2005 10:45 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-21-2007
bihani4u bihani4u is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 11
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 (permalink)  
Old 09-21-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,717
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 (permalink)  
Old 09-25-2007
bihani4u bihani4u is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 11
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 (permalink)  
Old 09-25-2007
borgeh borgeh is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 12
Quote:
Originally Posted by bihani4u View Post
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 (permalink)  
Old 09-25-2007
bihani4u bihani4u is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 11
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 10:02 AM..
  #6 (permalink)  
Old 09-25-2007
borgeh borgeh is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 12
Quote:
Originally Posted by bihani4u View Post
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 (permalink)  
Old 09-26-2007
Cameron's Avatar
Cameron Cameron is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2001
Location: Brisbane, Australia
Posts: 499
Quote:
Originally Posted by bihani4u View Post
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
Add the following at the start of your script:
#!/bin/ksh
. /etc/profile
. ${HOME}/.profile


Had a similar experience on HP-UX 11.2x some time ago.
If you still have an issue, add/remove other environment files that you may use.

HTH
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:47 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0