How to update the contents in a file conditionally? [message #142087] |
Thu, 13 October 2005 07:33 |
rajus19
Messages: 18 Registered: September 2005
|
Junior Member |
|
|
Hi All,
I have a data file which has two columns Location and the Count.
The file looks like this
India 1
US 0
UK 2
China 0
What I have to do is whenever I fails to login to Oracle then I have to add 1 to the count for that location.
Whenever my script fails to login to Oracle for a particular location, the script needs to find the record for that location and then change the count. I should not change the count for all the locations, instead I need to change the count only for that location.
Ex: Suppose if I am trying to login to Oracle for India location and fails to login then I have to update the count to 2.
Your help will be greatly appreciated.
Thanks in Advance
Raju
[Updated on: Thu, 13 October 2005 07:35] Report message to a moderator
|
|
|
|
|
Re: How to update the contents in a file conditionally? [message #142180 is a reply to message #142132] |
Thu, 13 October 2005 12:56 |
|
Mahesh Rajendran
Messages: 10708 Registered: March 2002 Location: oracleDocoVille
|
Senior Member Account Moderator |
|
|
#
# dblog is the name of the script
# I am executing it twice here.
oracle@mutation#dblog
-----------------------------------------------------
------------This is before the loop --
-- Each entry in this listing is in tnsnames.ora --
-- None except mutation and lawd is a valid entry --
-- a new file is generated at the end --
-- All counts are updated except valid ones --
-----------------------------------------------------
India 1
Canada 2
USA 3
mutation 4
UK 5
lawd 6
China 7
------------New file --------------------------------
------------end of file --------------------------------
India 2
Canada 3
USA 4
mutation 4
UK 6
lawd 6
China 8
#
# Execute again.
#
oracle@mutation#dblog
-----------------------------------------------------
------------This is before the loop --
-- Each entry in this listing is in tnsnames.ora --
-- None except mutation and lawd is a valid entry --
-- a new file is generated at the end --
-- All counts are updated except valid ones --
-----------------------------------------------------
India 2
Canada 3
USA 4
mutation 4
UK 6
lawd 6
China 8
------------New file --------------------------------
------------end of file --------------------------------
India 3
Canada 4
USA 5
mutation 4
UK 7
lawd 6
China 9
#
#This is the script
#Have your valid tnsentries (as in tnsnames.ora) in a file /tmp/dblist
#The script reads the file everytime and creates a new one.
#
oracle@mutation#cat dblog
#!/usr/bin/bash
echo -----------------------------------------------------
echo ------------This is before the loop --
echo -- Each entry in this listing is in tnsnames.ora --
echo -- None except mutation and lawd is a valid entry --
echo -- a new file is generated at the end --
echo -- All counts are updated except valid ones --
echo -----------------------------------------------------
cat /tmp/dblist
echo ------------New file --------------------------------
export ORACLE_HOME=/u01/app/oracle/product/9.2.0
cat /tmp/dblist | awk '{print $1}' | while read name
do
err=`sqlplus -s system/manager@$name <<EOF
set echo off
set head off
set feed off
WHENEVER SQLERROR EXIT SQL.SQLCODE
prompt
prompt
exit;
EOF`
if echo $err | grep "ERROR" > /tmp/junk1
then
awk -F" " '$1 ~/'$name'/ {print $1" "$2+1 }' /tmp/dblist >> /tmp/dblist.final
else
awk -F" " '$1 ~/'$name'/ {print $1" "$2 }' /tmp/dblist >> /tmp/dblist.final
fi
done
echo ------------end of file --------------------------------
mv /tmp/dblist.final /tmp/dblist
cat /tmp/dblist
[Updated on: Thu, 13 October 2005 13:05] Report message to a moderator
|
|
|
|