The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Operating Systems > AIX
.
google unix.com



AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
If statement - How to write a null statement april Shell Programming and Scripting 3 04-16-2008 01:14 PM
Need to execute the same statement Legend986 Shell Programming and Scripting 8 10-01-2007 04:59 PM
How do i execute in IF ELSE Statement laknar Shell Programming and Scripting 1 06-08-2007 02:54 AM
Script does not execute Insert Statement Amruta Pitkar Shell Programming and Scripting 4 08-24-2006 11:14 PM
How can I get an if statement to execute based on number of lines in a file? LordJezo Shell Programming and Scripting 6 05-14-2004 10:50 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-07-2008
Registered User
 

Join Date: Aug 2008
Posts: 18
Controling a statement to execute

Hi All
I have a script which runs a piece of JOB. The jobs are in sequence and if it fails at a particular job I wanted it to be started from the point where it failed.

What I did I prepared two properties file one which contains the entire List of the JOBS which are to be executed and the other in which I maintain the jobs which are successfully executed.

Before executing these jobs I check if its already executed and if so then I Skip the step.

The property file is having entry like
EODJOB=6000
EODJOB=6001
EODJOB=6002
.......

The script is as follows
#############################################

Code:
#! /usr/bin/ksh
# A test to automate the whole EOD

echo "Starting FX Front Office EOD..."

brn_num=$1
set -e on
echo "Running FX Front Office EOD for Branch Number: $brn_num "
echo "Running FX Front Office EOD for Branch Number: $brn_num" > error.txt 2>&1

rootdir=$PWD
fullpropfile=$rootdir/FULL_FX_EOD_JOB.properties
completedpropfile=$rootdir/COMPLETED_FX_EOD_JOB.properties

if [  `grep -c "^EODJOB=" $fullpropfile` -gt 0 ]
    then
    echo "Running the EOD Process"
    for i in `grep "^EODJOB=" $fullpropfile | cut -f2 -d"="`
    do
        
        if [  `grep -c "^EODJOB="$i $completedpropfile` -gt 0 ]
            then 
            echo $i Job is already executed for branch =$brn_num and hence skipping the job..........
        else
            echo executing the job $i for branch=$brn_num
            . ./runEod.sh $i $brn_num>> error.txt 2>&1
                if [ $# -eq 0 ]   #ok execution
                    then
                    echo $i Process completed for Branch No:=$brn_num
                    echo writing into job into completed list 
                    echo 'EODJOB='$i>>COMPLETED_FX_EOD_JOB.properties
                fi
        fi

    done
echo "FX Front Office EOD for Branch Number: $brn_num run successfully"
fi
echo erasing the completed job list
echo "">$completedpropfile
###############################################
The problem is that I am clering the file which contains the completed job entry at the last.
And say if a job fails it goes and clear the file.

What i need is that only if the entire file is sucessfully executed then only I should clear the file and if the scripts fails in between it should skip this step.

Kindly suggest any way

Last edited by bakunin; 10-07-2008 at 07:38 PM.. Reason: Please use code-tags when posting scripts.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-08-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
 

Join Date: Sep 2007
Location: Germany
Posts: 1,681
Note: This is not AIX specific, should have been posted in the Shell Scripting subboard; recall this next time please

Quote:
The problem is that I am clering the file which contains the completed job entry at the last.
And say if a job fails it goes and clear the file.

What i need is that only if the entire file is sucessfully executed then only I should clear the file and if the scripts fails in between it should skip this step.
I am not sure how you check if your job was ok or not - I guess you will have to parse your error.txt... ?
So just react to this and not simply erase your file in the end, wether it was succesful or not, as you do it atm.
Not sure if your runEod.sh produces an exit code you can use to decide what to do next.
Since you have this script and probably wrote it yourself, I guess you can easily adjust to your efforts?
Reply With Quote
  #3 (permalink)  
Old 10-08-2008
Registered User
 

Join Date: Aug 2008
Posts: 18
Many thanks for your inputs.
The reason i posted here in AIX was because the server is IBM AIX and hence i posted here. Will take care of the point you mentioned as it makes easier to manage things if placed in correct path.

However I think there is a way in shell scripting by which say if a script fails at a particular point then in that case it stops execution there itself and does not proceed further. How to achieve that?

Last edited by Prashantckc; 10-08-2008 at 06:41 AM..
Reply With Quote
  #4 (permalink)  
Old 10-08-2008
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
 

Join Date: Sep 2007
Location: Germany
Posts: 1,681
Ok, no problem

Not that I know of...
Error handling is usually done via Exit/Return Codes and checking them with if/fi and additionally using break/continue to steer through the logic of the script, if needed.

For example if commands in your script are executed, check the value of $? and if it is not zero, usually something has gone wrong.
Reply With Quote
  #5 (permalink)  
Old 10-08-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,293
Wink One possible approach to solve

While in this section of code:
Code:
if [ $# -eq 0 ]   #ok execution
could you add:
Code:
ok_exec="Y"
then, at the end, do the following:
Code:
if [ $ok_exec = "Y" ]
   then
   echo erasing the completed job list
   echo "">$completedpropfile
fi
Reply With Quote
  #6 (permalink)  
Old 10-08-2008
bakunin bakunin is online now Forum Staff  
Bughunter Extraordinaire
 

Join Date: May 2005
Location: In the leftmost byte of /dev/kmem
Posts: 1,474
Quote:
Originally Posted by Prashantckc View Post
However I think there is a way in shell scripting by which say if a script fails at a particular point then in that case it stops execution there itself and does not proceed further. How to achieve that?
Probably you might want to read the ksh documentation about "traps". It seems to me that this is doing exactly what you want.

I hope this helps.

bakunin
Reply With Quote
Google The UNIX and Linux Forums
Reply

Bookmarks

Tags
None

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:




All times are GMT -4. The time now is 07:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66