Sponsored Content
Top Forums UNIX for Dummies Questions & Answers update value in a file using variable passed via unix script Post 302467387 by jsmithstl on Friday 29th of October 2010 07:15:36 AM
Old 10-29-2010
You don't give enough details on how your calling the script to check for the Oracle errors, but here's an example of how to accomplish what you're trying to do. You should be able to incorporate this into your existing scripts. If you have questions, let me know.

I don't know what shell you are using. My example uses ksh.

I created two files:

Code:
cat job1.out
line1

cat restart_job1.job 
01234567890123456789

Here's what my script looks like:
Code:
cat chk_job.ksh 
#!/bin/ksh

#
# Define variables.
#
# These values can be passed in
# or you can determine them with 
# logic.  It all depends on how 
# you're calling this script.
#
# For this test we'll just set them
# locally in the script.
#
JOB_STEP=9

#
# Assuming your job logs and restart files
# are using standard naming conventions:
#
#    ie:  job log file:  job1.out
#         restart file:  restart_job1.job
#
JOB_LOG=job1.out
RESTART_FILE=restart_$(echo "${JOB_LOG}" | cut -d\. -f1).job
RESTART_LINE=$(cat ${RESTART_FILE})

#
# Count the number of lines containing
# an Oracle error.
#
ORA_ERROR_COUNT=$(grep "ORA-" job1.out | wc -l)

if [ "${ORA_ERROR_COUNT}" -gt 0 ]; then
   echo "ERROR FOUND"

   #
   # You can change restart_job1.job file
   # at this point.
   #
   echo "${RESTART_LINE}" | sed "s/^0/${JOB_STEP}/" > ${RESTART_FILE}

else
   echo "JOB COMPLETED SUCCESSFULLY"
fi

exit 0

Here's the results based on NO Oracle error being found:

Code:
./chk_job.ksh
JOB COMPLETED SUCCESSFULLY

...and restart_job1.job remains unchanged
Code:
cat restart_job1.job 
01234567890123456789

Now we put an error in job1.out and rerun the chk_job.ksh script:
Code:
cat job1.out
ORA- line1

The error is found and restart_job1.job is updated, replacing the 0 in column one with the job_step (9).
Code:
./chk_job.ksh 
ERROR FOUND

cat restart_job1.job 
91234567890123456789

I hope this helps. Good Luck

Last edited by jsmithstl; 10-29-2010 at 08:18 AM.. Reason: Corrected typos in the comments.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl script variable passed to Oracle query

Hi All, I pass a Perl script variable, whch is passed to a query to be prepared. But the problem is I have special character like '&' in this variable which are handled in a special way by the Oracle query parser. How do I get over this? my $cust_name='A&B'; my $sql="Select cust_short_name... (1 Reply)
Discussion started by: rahulrathod
1 Replies

2. UNIX for Advanced & Expert Users

unix script for update or insert records from a file to a oracle table

Hi, I have delimited file(|). Sample data: 1|name|50009|DS24|0|12 2|name|30009|DS24|0|13 3|name|20409|DS24|0|14 4|name|20009|DS24|0|15 5|name|10009|DS24|0|16 I want to load this data into a oracle table (update and insert) Please help me the commands and also... (1 Reply)
Discussion started by: unihp1
1 Replies

3. Shell Programming and Scripting

how to find the path of a file when it is passed as ....filename(parameter) to script

hi unix guru's..................:confused: question is posted in the #3 permalink shown below. (3 Replies)
Discussion started by: yahoo!
3 Replies

4. Shell Programming and Scripting

what is the maximum length of a unix shell variable which can be can passed to plsql

what is the maximum length of a unix shell variable which can be can passed to plsql variable:( (1 Reply)
Discussion started by: alokjyotibal
1 Replies

5. Shell Programming and Scripting

Shell script in tracking both the passed and failed login in a unix server

Can you help me in providing the following output or a quite similar to this from a shell script ? *** Logins Summary Information ***** ---------------------------------- Failed Login Attempts for Invalid Accounts Date Time IP-ADD Account ... (0 Replies)
Discussion started by: linuxgeek
0 Replies

6. Shell Programming and Scripting

Getting the file name passed to a shell script

Hi all I want to use the filename passed into a shell script within the shell it self. The file will be passed as shown below ./myScript < myFile.file i tried $1 but i think since myFile is not passed as a command line arg its not saving the file name in $1 any help is appreciated. (5 Replies)
Discussion started by: sridanu
5 Replies

7. Shell Programming and Scripting

Grepping file and returning passed variable if the value does not exist in file at all.

I have a list of fields that I want to check a file for, returning that field if it not found at all in the file. Is there a way to do a grep -lc and return the passed variable too rather then just the count? I am doing some crappy work-around now but I was not sure how to regrep this for :0 so... (3 Replies)
Discussion started by: personalt
3 Replies

8. UNIX for Advanced & Expert Users

Value of variable not getting passed in child script

Hi, I am facing a challenge in fixing an issue in my installation scripts.Here is a situation: There are 3 files which are invoked at a below given order: Installer.ksh----->Installer.xml(Ant script)------->common.ksh I am outputting a message from common.ksh at a terminal, after that trying to... (3 Replies)
Discussion started by: baig_1988
3 Replies

9. Shell Programming and Scripting

In the sh file variable is not being passed on.

I am having difficulties with the fllowing script: !/bin/sh voicemaildir=/var/spool/asterisk/voicemail/$1/$2/INBOX/ echo `date` ':' $voicemaildir >> /var/log/voicemail-notify.log for audiofile in `ls $voicemaildir/*.wav`; do transcriptfile=${audiofile/wav/transcript} ... (4 Replies)
Discussion started by: ghurty
4 Replies

10. UNIX for Dummies Questions & Answers

How to Update DB table from txt file using CRONJOB in Unix Shell Script

Hi Experts, can guide how we can Update a Database Table using a txt file source Using Unix Shell Scripts. What are the Cron Jobs codes can written to Update DB table. txt file contains record like data. US 09/03/2012 User DocType DocID. these above feilds in txt files need to be updated in... (4 Replies)
Discussion started by: mahesh.sap
4 Replies
All times are GMT -4. The time now is 07:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy