UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old July 1st, 2004, 01:07 PM
roliee roliee is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 7 roliee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation Help! Unix newbie ksh problem

hi,
a newbie in unix wants help from the expert guys.
i have to write a ksh script which does the following:
1. open sql plus session.
2. read (say path to the unix directories) from an oracle table. It will return me 2 records (say, path for US files and path for UK files )

the dir structure is:
for US: /usr/us
for UK: /usr/uk

The above dir path is stored in a db table.

now each of these dir's will hav 2 subdirectories: internal and external.

each of the subdir's (internal and external) will have many ".loc" files.


3. My requirement is:
--------------algorithm
1. open the sql plus session

2. select "path" from the db table (returns 2 paths--viz: /usr/us and /usr/uk)

3. for each of these main dirs, check for the "external" subdir.--this should be a loop
if external subdir is there---count the no of .loc files, say c
----loop till count is c for each .loc file
----------process the .loc file
----end loop
if internal subdir is there
---count the no of .loc files, say c
----loop till count is c for each .loc file
----------process the .loc file
----end loop


Guys can u pls provide me some similar code which can help me for the same. i am using korn shell for the scripts

Thanks

Reply With Quote
  #2  
Old July 1st, 2004, 01:21 PM
jim mcnamara jim mcnamara is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,299 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 8 h 41 m 52 sec
Reputation Power: 47
This is a start - you get to finish off your requirements
Code:
/*myfile1.sql you change this  */
select 'UK' from dual;

Code:
/*myfile2.sql */
select 'US' from dual;


Code:
#!/bin/ksh
instance="MYINST"
UIPW=user/password@$instance

` echo "
            $UIPW
             set lines 20
             set head off
             @/path/to/myfile1
             @/path/to/myfile2 |
              $ORACLE_HOME/bin/sqlplus -s ` |
while read result
do
     echo $result
done

You'll have to ignore some blank lines. Or you can rewrite it to run sqlplus twice.

Reply With Quote
  #3  
Old July 1st, 2004, 01:38 PM
roliee roliee is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 7 roliee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thnx jim for the headstart

i will take it as the starting point.
i have a query regarding the same.

im getting 2 records from the select query that i will fire
to the db using the sql plus that i fire from the script.
So i will have a recordset output frm the select statement.

How can i assign the recortset which i am getting from the select inside the script?is there any kind of var which i can use for the same(like array or something)?

say if the sql query being fired by me is:

select path from world_table; it returns 2 records : /usr/us and /usr/uk.

i need to set them to a recordset so that i can loop as per the no of records i receive.

Reply With Quote
  #4  
Old July 1st, 2004, 02:48 PM
jim mcnamara jim mcnamara is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Posts: 1,299 jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level)jim mcnamara User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 8 h 41 m 52 sec
Reputation Power: 47
In the example I gave you, result contains the output of the qeuries, one query at a time.

Reply With Quote
  #5  
Old July 1st, 2004, 04:08 PM
roliee roliee is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 7 roliee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thnx jim
will try to apply the same logic.

Reply With Quote
  #6  
Old July 9th, 2004, 09:06 AM
roliee roliee is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 7 roliee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation Unix script to be reviewed for my requirememts

Hi guys
can u pls let me know if anythings wrong with the below script for my case.

Thanks in advance

#!/bin/ksh
###########################################user name
username='sys'

# directory to pwd file
pswdFile=`/cat /ora0/oracle/passwd/sys`;
#read the pwd file for the pwd

cat PSWD < $pswdFile

# correctly configure SID
SID='mySid'

# utl_out='/app/oracle/admin/mySid/utlout/'

#Run a sql file which contains the sql query
#Save the returning MULTIPLE records into the unix array data type.
set -A results `sqlplus -s $username/$PSWD@$SID WatchSql.sql`
size_of_array=${#results[@]}
let counter=0
while [ $counter -lt $size_of_array ]
do
echo " ${results[$counter]} "
### Loop for each FILE PATH(main directories)
#### eg: /country/canada/
temp= ${results[$counter]}

# path is not a dir, return
if [[-d $temp ]] then
return
fi

# path is indeed a directoty
#check if INSURANCE directory is there

feedDir=$temp/INSURANCE

if [[-d $feedDir && -n $feedDir ]] then
## yes INSURANCE dir exists

# for each file ending in HNN,
# move the file to utl_out directory
# invoke the sql routine passing the original directory(incl INSURANCE)
# and the filename of the file moved.
# moves the resulting output file and error file to the
# originating directory(including INSURANCE)

# get all files ending in .HNN in this directory
#tempFile to store one ascii file name
for filename in ${tempFile:+$feedDir/}*.HNN ; do

#extract the filename from the path for passing to the parser routine.
#file name eg: JUNE.HNN
fileName=${tempFile##/*/}

#move the file to utl_out dir for processing
mv $tempFile $utl_out

#change dir to utl_out
cd $utl_out

# invoke the parsefile routine
sqlplus -s username/$PSWD@$SID<<-ENDSQL
exec PROCEDURE(feedDir,fileName)
exit
ENDSQL

#check if any .LOG files are generated in the current dir(i.e utl_out)
if [[-a $fileName.LOG]]
#move it to original dir(INSURANCE)
mv $fileName.LOG $feedDir
fi

##clean the var
fileName=""
tempFile=""
done
### end processing all the Ascii files
fi

let counter=counter+1
done

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Help! Unix newbie ksh problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway