update value in a file using variable passed via unix script
I have a file in my unix directory called "restart_job1.job". Below is a sample of the script where I am doing a 'grep' to check specifically for an oracle error. If the value 'ORA-" is found, I set a variable to hold the return code value (job1_return_code). If the return code is non zero, I exit the script.
What I need to do update the file "restart_job1.job". There will only be 1 line in this file and it is set to have a value of 0 in the first byte on the first line. In this case, I want to update the file and change the 0 to the job step#.
1) How do I define a variable for the job step? I will setting that value in the failed return code logic.
2) How do I update the "restart_job1.job" file with the value in the job step variable?
Here's my script so far:
It is probably pretty obvious that I am fairly new to unix scripting. Any guidance would be appreciated!!
Moderator's Comments:
Use [code] and [/code] tags when posting code, data or logs etc. to preserve formatting and enhance readability, thanks.
I'm a bit worried about this line. What is it intended to do?
Please give examples of "the job step#" in one-digit, two-digit, three-digit form.
Is there anything else in the single record of the file restart_job1.job , and is it a normal unix text file?
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:
Here's what my script looks like:
Here's the results based on NO Oracle error being found:
...and restart_job1.job remains unchanged
Now we put an error in job1.out and rerun the chk_job.ksh script:
The error is found and restart_job1.job is updated, replacing the 0 in column one with the job_step (9).
I hope this helps. Good Luck
Last edited by jsmithstl; 10-29-2010 at 08:18 AM..
Reason: Corrected typos in the comments.
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)
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)
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)
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)
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)
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)
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)
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)