Korn Shell and Oracle


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Korn Shell and Oracle
# 8  
Old 02-16-2009
pareshan:

your bdf output is trying to squeeze itself down to fit your teminal width. try piping it through 'grep ^ ' such as:
Code:
bdf |grep ^

otherwise, if there's additional spaces causing you problems, you can also pipe the above output through tr to squeeze out spaces too:
Code:
bdf |grep ^ |tr -s [:space:]

lastly, if you'd really want to get wild, you pipe all of the above into Rahul's earlier awk script too (although it might be somewhat slower, and less resilient for errors, than sqlldr if there's too many records). sqlldr is nice in that it ensures at least a basic transaction commit level...and since it creates a bad file, etc, it's helpful when the script might be supported by additional folks:

Code:
bdf |grep ^ |tr -s [:space:] |awk -v serv=$server '
{print "insert into table1 values (~" serv "~,~" $1 "~,~" $6 "~," $2 "," $3 "," $4 "," $5 " );" }
' | sed -e "s/~/'/g" -e 's/%//' > $sqlfile

# 9  
Old 02-16-2009
Thanks alot but nothign really working out here.

I think I can do rest if i get solution of just this one as I mentioned below

while im doing bdf if the output is in two lines then i want to shift that in one line rest removing spaces and all i can do it using perl. Just you can see some of them are in one line and some of then are in two lines just i need help with those whose result came in two lines. something like if the value is in two lines then shift it to one line and im not able to implement it thats my problem. can be in ksh or perl i dont care.

If I can change all the outputs which are like this
/dev/vghome_old/lvol1
23552000 10375127 12353732 46% /usr/local/g1/dev/vgapp02/lvol1

into this kind of outputs like the other ones
/dev/vgapp/lvol9 25624576 23454180 2138564 92% /mps
then rest that oracle and deleting extra spaces I can handle.. just I need help in this one.



bdf_output

/dev/vg3psw/lvol9 5120000 1286387 3594077 26% /usr/local/g1_3.2_SE
/dev/vghome_old/lvol1
23552000 10375127 12353732 46% /usr/local/g1/dev/vgapp02/lvol1 153616384 100802161 49543296 67% /tuxappl
/dev/vg00/lvol6 1540096 44424 1488456 3% /tmp
/dev/vgapp-io/lvol1
199155712 153617264 45361864 77% /tlgvar
/dev/vgapp/lvol3 2097152 24344 2056680 1% /opcode
/dev/vgapp/lvol9 25624576 23454180 2138564 92% /mps
/dev/vghome_old/lvol5
5144576 185360 4649319 4% /lsms_tool
/dev/vgapp-io/lvol2
2097152 5208 2075800 0% /logs
/dev/vgdbcommon/lvol1
18432000 1517936 16786512 8% /logs/ORACLE
/dev/vghome/lvol1 62898176 54860264 8037912 87% /home
/dev/vgapp/lvol8 524288 290587 219125 57% /emc
/dev/vgd2bl12d_2/lvol3
20512768 6129 19224982 0% /csmtier1/logs
/dev/vgapp/lvol10 1048576 6334 977155 1% /csmscripts
/dev/vghome_old/lvol6
51707904 3864 51300112 0% /ora_D2BL12B_4

/dev/vg27/lvol3 204865536 197661672 7147648 97% /ora_D2BL42A_3
/dev/vg27/lvol2 307232768 26120 304806672 0% /ora_D2BL42B_2
/dev/vg27/lvol1 307232768 287320072 19757192 94% /ora_D2BL43A_2
/dev/vg27/lvol4 20578304 9825080 10669224 48% /ora_fbf_1

Just you can see some of them are in one line and some of then are in two lines just i need help with those whose result came in two lines. something like if the value is in two lines then shift it to one line and im not able to implement it thats my problem. can be in ksh or perl i dont care


thanks alot
help plz
# 10  
Old 02-16-2009
I found the solution now and I solved it and correct code is


#!//opt/perl/bin/perl
use strict;
use warnings;
my ($filesystem);
foreach (qx(bdf)) { ##executing bdf command here
next if/^Filesystem/; ##Skip the header line
if(!/%/) { ##remember on next line if no percentage on this line
chomp; ##clean up the new line
$filesystem = $_; ## remember
next;
}
$_ = $filesystem . $_ if /^\s/; ## add filesystem for wrapped lines
#next if /^\w+:/; #skip NFS mount with ":" in first word ##To skip the NFS mount
#chomp;
s/% / /; ## strip percentage sign
s/\s+/ /g; ## replace all tabs and spaces with just 1 space
my ($fs, $kbytes, $used, $avail, $pct_used, $mount) = split; ## now have each column
in a variable
## do anything you like with the columns (like preparing an oracle insert)
##print $_, "\n" ; # just to prove new glued line
##print qq(fs=$fs used=$pct_used \n);
print qq($fs $kbytes $used $avail $pct_used $mount\n);
}

this will help to format the bdf and even can remove NFS mount file systems if you comment that out.

Now I want to insert value into oracle table which has format

Name Null? Type
----------------------------------------- -------- ----------------------------
SERVER_ID NOT NULL NUMBER(6)
FS_LOCAL_NAME NOT NULL VARCHAR2(200)
LOCAL_MOUNT NOT NULL CHAR(1)
TOTAL_SPACE NOT NULL NUMBER(10)
USED_SPACE NUMBER(10)
SPACE_AVAILABLE NUMBER(10)
PERCENTAGE_USED NUMBER(3,2)

Here I have one problem because all of the required fields are in the above bdf output but SERVER_ID.

Could you guys help how can i insert into that table using the above code because the script is in perl but anything is ok whether perl or korn shell if it works

thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

pass value from Oracle sql to Korn shell

Hi All , I am trying to pass a value from sqlplus to korn shell . There is a table tab1 in Oracle that has a column userdate. I need to pass the userdate to the korn shell . This is what I am doing . VALUE=`sqlplus -silent username/password << END set pagesize 0 feedback off verify off... (14 Replies)
Discussion started by: megha2525
14 Replies

2. Shell Programming and Scripting

Korn Script to connect and query oracle database

I've been sent the following script to finish. It's supposed to connect to an oracle database, query it, and send an email if the query result value is one or more. Currently it isn't connecting properly, just giving the following error: ERROR: ORA-01017: invalid username/password; logon denied... (2 Replies)
Discussion started by: jackmorgan2007
2 Replies

3. Shell Programming and Scripting

Bourne shell & Korn shell

Could some one tell me the difference btw Bourne shell and the Kshell? Which is more flexible and reliable in terms of portability and efficiency. When i type the following command .. $ echo $SHELL yields me /bin/sh Does this tells me that I am in Bourne shell. If yes, how can i get... (6 Replies)
Discussion started by: bobby1015
6 Replies

4. Shell Programming and Scripting

Korn shell program to parse CSV text file and insert values into Oracle database

Enclosed is comma separated text file. I need to write a korn shell program that will parse the text file and insert the values into Oracle database. I need to write the korn shell program on Red Hat Enterprise Linux server. Oracle database is 10g. (15 Replies)
Discussion started by: shellguy
15 Replies

5. Shell Programming and Scripting

How to activate Korn Shell functionnalities in Bourne Shell

Hi All I have writing a Korn Shell script to execute it on many of our servers. But some servers don't have Korn Shell installed, they use Borne Shell. Some operations like calculation don't work : cat ${file1} | tail -$((${num1}-${num2})) > ${file2} Is it possible to activate Korn Shell... (3 Replies)
Discussion started by: madmat
3 Replies

6. UNIX for Advanced & Expert Users

Need Help for Using Oracle Cursors in Shell Script Korn

Hi, My Oracle Stored procedure returns sys_refcursor to shell script. I have to iterate through it in script and use those retrieved values further in my script. I am using K Shell Scrpting. Stored Procedure is: create or replace PROCEDURE p_test(job_id IN VARCHAR2, c1 OUT SYS_REFCURSOR)... (0 Replies)
Discussion started by: rajeshorpu
0 Replies

7. Shell Programming and Scripting

how to convert from korn shell to normal shell with this code?

well i have this code here..and it works fine in kornshell.. #!/bin/ksh home=c:/..../ input=$1 sed '1,3d' $input > $1.out line="" cat $1.out | while read a do line="$line $a" done echo $line > $1 rm $1.out however...now i want it just in normal sh mode..how to convert this?... (21 Replies)
Discussion started by: forevercalz
21 Replies

8. Shell Programming and Scripting

KORN Shell - Spawn new shell with commands

I want to be able to run a script on one server, that will spawn another shell which runs some commands on another server.. I have seen some code that may help - but I cant get it working as below: spawn /usr/bin/ksh send "telnet x <port_no>\r" expect "Enter command: " send "LOGIN:x:x;... (2 Replies)
Discussion started by: frustrated1
2 Replies

9. UNIX for Dummies Questions & Answers

Executing Oracle Stored Procs from Korn Shell

Can someone tell me how to execute an Oracle Stored Procedure from a Korn Shell Script. Previously, I'm able to execute standard sql using the following:- The_Output=`sqlplus................. << EOF select count(*) from abc / ... (3 Replies)
Discussion started by: Vinny_Mitchell
3 Replies

10. UNIX for Advanced & Expert Users

Oracle To Korn Shell Array

I'm attempting to populate an array in ksh using the following command: set -A $(SELECT_INVOICE | sed '/^$/d') SELECT_INVOICE is a function that executes the SQL query. Problem: Some of the invoice numbers have alpha characters with spaces(example: OVEN MICRO). The Korn shell is treating... (1 Reply)
Discussion started by: kdst
1 Replies
Login or Register to Ask a Question