Controling a statement to execute


 
Thread Tools Search this Thread
Operating Systems AIX Controling a statement to execute
# 1  
Old 10-07-2008
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 08:38 PM.. Reason: Please use code-tags when posting scripts.
# 2  
Old 10-08-2008
Note: This is not AIX specific, should have been posted in the Shell Scripting subboard; recall this next time please Smilie

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?
# 3  
Old 10-08-2008
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 07:41 AM..
# 4  
Old 10-08-2008
Ok, no problem Smilie

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.
# 5  
Old 10-08-2008
Hammer & Screwdriver 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

# 6  
Old 10-08-2008
Quote:
Originally Posted by Prashantckc
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

2. Shell Programming and Scripting

How to pass tablenames from a file to shell script to execute create statement in DB2

Hi, I am new to Shell Scripting, and I need to create nicknames for 600 tables in db2. I have the file names in a text file and i have to pass these table names to a shell script create nicknames in db2. Can some one please help me in this regard. (1 Reply)
Discussion started by: kamalanaatha
1 Replies

3. Shell Programming and Scripting

Execute and log each statement/block SQL file

Hi friends, I would like to get some help on the following requirement. I have a SQL file with following things, select 1 from dual; select user from dual; select sysdate from dual; BEGIN PL/SQL Code END; / This file will be saved as sql file. When I run my expected shell script,... (1 Reply)
Discussion started by: ssnair
1 Replies

4. Shell Programming and Scripting

Need help in controling execution rate of script in shell

I want to control the speed of execution of a script, There are 1000 lines in script, i want 100 lines to be executed in 10 seconds and from 11th second execution from 101 line should start, again so on. Please help me in creating the script. Thanks, cmaniar (1 Reply)
Discussion started by: cmaniar
1 Replies

5. Shell Programming and Scripting

for each value in an array, execute select statement

Hello All, I am new to shell scripting. I am working on Solaris O/S, bash script and sybase programming. I want to loop through multiple values in an array and for each value, I want to select a row from the database. following is the code written for it. output="loop.csv" ... (8 Replies)
Discussion started by: arundhati_s
8 Replies

6. Shell Programming and Scripting

How is use sselect statement o/p in insert statement.

Hi All, I am using Unix ksh script. I need to insert values to a table using the o/p from a slelect statement. Can anybody Help! My script looks like tihs. ---`sqlplus -s username/password@SID << EOF set heading off set feedback off set pages 0 insert into ${TB_NAME}_D... (2 Replies)
Discussion started by: nkosaraju
2 Replies

7. Shell Programming and Scripting

Need to execute the same statement

I have written a script for converting an IP address into its corresponding AS number in PHP. But based on the timing analysis, I've observed that it takes a long time to process large number of entries. So I need to do something directly in unix. What method would one suggest for this purpose? ... (8 Replies)
Discussion started by: Legend986
8 Replies

8. Shell Programming and Scripting

How do i execute in IF ELSE Statement

ls -ld /path/to/dir1 path/to/dir2 | awk '{print $8}' how to execute above script in IF ELSE Statement. Pls iam new to Unix (1 Reply)
Discussion started by: laknar
1 Replies

9. Shell Programming and Scripting

Script does not execute Insert Statement

Hi I have a text file , contents are Line1:field1,field2,field3,field4,field5,field6.......field20 Line2:field1,field2,field3,field4,field5,field6.......field20 Line3:field1,field2,field3,field4,field5,field6.......field20 ....and so on... I want to read this file and insert the data into... (4 Replies)
Discussion started by: Amruta Pitkar
4 Replies

10. Shell Programming and Scripting

How can I get an if statement to execute based on number of lines in a file?

I need to have an if statement in a script to run if there are certain processes running. Easiest way I can see to do this is to run a ps and grep the results based on what I am looking for: $ ps -ef | grep wtrs --- webtrend 5046 1 0 May 12 ? 0:28 /webtrends/versions/6.1/wtrs_ui... (6 Replies)
Discussion started by: LordJezo
6 Replies
Login or Register to Ask a Question