in reply to Re^2: export table to text.
in thread export table to text.

sample output from script primary_only_automation_enable_KJ_create or...

Perhaps you want something like this?

#!/usr/bin/perl -w use strict; my $raw_data; open(my $in, '-|', 'sh my_shell_script.sh arg1 arg2') or die "open( +in): $!\n"; while (<$in>) { $raw_data .= $_; } my %pairs = split /_KJ_/, $raw_data; for (keys %pairs) { open(my $out, '>>', $_) or die "open(out): $!\n"; print $out %pairs{$_}; }

Thanks for improving the formatting of your nodes. You could improve it further still by wrapping anything that's not English in code tags, like so:

<c>$some = code($goes_here);</c>

or:

<c>sr.no. Name CodeBlock ...</c>

Hint hint ;)


email: perl -e 'print reverse map { chr( ord($_)-1 ) } split //, "\x0bufo/hojsfufqAofc";'
'Under no circumstances should you program the way I say to because I say to; program the way you think expresses best what you're trying to accomplish in the program. And do so consistently and ruthlessly.' --Rob Pike

Replies are listed 'Best First'.
Re^4: export table to text.
by Anonymous Monk on Oct 21, 2008 at 09:10 UTC

    Hi,
    I did struggle quite a while to get this right but am again
    back to where i started from. I am still unable to get
    this work. Below is the code that I am using

    Any suggestions?

    #!/usr/bin/perl # Initialize Server Specific Variables $server = <STDIN>; $user = <STDIN>; $password = <STDIN>; $omnihome = "/app/netcool/omnibus"; # Initialize Variables that define SQL Login Commands $sqsh_string = "${omnihome}/bin/nco_sql.sqsh -server $server -user $us +er -password $password"; #---------------------------------------------------------- # Script Body #---------------------------------------------------------- #$running = `$test`; # Initialize SQL Action Statements $sql_select_Procedure = "select ProcedureName, SQLBlock from persist.p +rocedures"; # Select ProcedureName and SQLBLock &GetRawProcedureData; my %pairs = split /_KJ_/, $raw_data; for (keys %pairs) { open(my $out, '>>', $_) or die "open(out): $!\n"; print $out %pairs{$_}; } #---------------------------------------------------------- # Subroutines #---------------------------------------------------------- sub GetRawProcedureData { $raw_data = `$sqsh_string <<'EOF'; $sql_select_Procedure go quit EOF`; }

    The raw output from DB query.

    output from query script: send_email_yvs_kj_ create or replace procedure send_email (in node character(1), in sever +ity integer, in subject character(1), in email character(1), in summa +ry character(1), in hostname character(1)) executable '$OMNIHOME/util +s/nco_mail' host hostname user 0 group 0 arguments '\''+node+'\'', se +verity,'\''+subject+'\'','\''+email+'\'','\''+summary+'\'';_yvs_kj_ jinsert_yvs_kj_ create or replace procedure jinsert( in serial int, in uid int, in t +stamp utc, in msg char(4080) )begin---- Procedure inserts a record i +nto the alerts.journal table. Automations that -- require journal ent +ries should execute this procedure.---- Usage: -- call procedure ji +nsert( old.Serial, %user.user_id, getdate, 'This is my journal entry' +);-- insert into alerts.journal values ( journal_keyfie +ld( to_int( serial ), to_int( uid ), tstamp ), -- KeyField + serial, -- Serial uid, + -- UID tstamp, + -- Chrono split_multibyte(msg, 1, 255), -- + Text1 split_multibyte(msg, 2, 255), -- Text2 + split_multibyte(msg, 3, 255), -- Text3 spli +t_multibyte(msg, 4, 255), -- Text4 split_multibyte(m +sg, 5, 255), -- Text5 split_multibyte(msg, 6, 255), + -- Text6 split_multibyte(msg, 7, 255), -- Text7 + split_multibyte(msg, 8, 255), -- Text8 + split_multibyte(msg, 9, 255), -- Text9 split_multi +byte(msg, 10, 255), -- Text10 split_multibyte(msg, 11 +, 255), -- Text11 split_multibyte(msg, 12, 255), -- +Text12 split_multibyte(msg, 13, 255), -- Text13 + split_multibyte(msg, 14, 255), -- Text14 sp +lit_multibyte(msg, 15, 255), -- Text15 split_multibyt +e(msg, 16, 255) -- Text16 );end_yvs_kj_ convert_severity_yvs_kj_ create or replace procedure convert_severity (IN omnibus_severity INTEGER, OUT tec_severity INTEGER) BEGIN if (omnibus_severity = 5) then set tec_severity = 50 elseif (omnibus_severity = 4) then set tec_severity = 40 elseif (omnibus_severity = 3) then set tec_severity = 40 elseif (omnibus_severity = 2) then set tec_severity = 30 elseif (omnibus_severity = 1) then set tec_severity = 10 else set tec_severity = 10 end if; END_yvs_kj_
Re^4: export table to text.
by kirtivardhan (Initiate) on Oct 21, 2008 at 15:03 UTC

    Hi,
    I did struggle quite a while to get this right but am again
    back to where i started from. I am still unable to get
    this work. I am warned of printing on closed file handle. I am not sure how to resolve it.
    Below is the code that I am using

    Any suggestions?

    #!/usr/bin/perl # Initialize Server Specific Variables $server = <STDIN>; $user = <STDIN>; $password = <STDIN>; $omnihome = "/app/netcool/omnibus"; # Initialize Variables that define SQL Login Commands $sqsh_string = "${omnihome}/bin/nco_sql.sqsh -server $server -user $us +er -password $password"; #---------------------------------------------------------- # Script Body #---------------------------------------------------------- #$running = `$test`; # Initialize SQL Action Statements $sql_select_Procedure = "select ProcedureName, SQLBlock from persist.p +rocedures"; # Select ProcedureName and SQLBLock &GetRawProcedureData; %val = split(/_yvs_kj_/, $raw_data); while (($name, $code) = each (%val)) { open (FILE, $name) or die ("jhand"); print FILE $code; print "$name\n"; print "$code\n"; } close FILE; #---------------------------------------------------------- # Subroutines #---------------------------------------------------------- sub GetRawProcedureData { $raw_data = `$sqsh_string <<'EOF'; $sql_select_Procedure go quit EOF`; }

    This is the output of my sql query

    output from query script: send_email_yvs_kj_ create or replace procedure send_email (in node character(1), in sever +ity integer, in subject character(1), in email character(1), in summa +ry character(1), in hostname character(1)) executable '$OMNIHOME/util +s/nco_mail' host hostname user 0 group 0 arguments '\''+node+'\'', se +verity,'\''+subject+'\'','\''+email+'\'','\''+summary+'\'';_yvs_kj_ jinsert_yvs_kj_ create or replace procedure jinsert( in serial int, in uid int, in t +stamp utc, in msg char(4080) )begin---- Procedure inserts a record i +nto the alerts.journal table. Automations that -- require journal ent +ries should execute this procedure.---- Usage: -- call procedure ji +nsert( old.Serial, %user.user_id, getdate, 'This is my journal entry' +);-- insert into alerts.journal values ( journal_keyfie +ld( to_int( serial ), to_int( uid ), tstamp ), -- KeyField + serial, -- Serial uid, + -- UID tstamp, + -- Chrono split_multibyte(msg, 1, 255), -- + Text1 split_multibyte(msg, 2, 255), -- Text2 + split_multibyte(msg, 3, 255), -- Text3 spli +t_multibyte(msg, 4, 255), -- Text4 split_multibyte(m +sg, 5, 255), -- Text5 split_multibyte(msg, 6, 255), + -- Text6 split_multibyte(msg, 7, 255), -- Text7 + split_multibyte(msg, 8, 255), -- Text8 + split_multibyte(msg, 9, 255), -- Text9 split_multi +byte(msg, 10, 255), -- Text10 split_multibyte(msg, 11 +, 255), -- Text11 split_multibyte(msg, 12, 255), -- +Text12 split_multibyte(msg, 13, 255), -- Text13 + split_multibyte(msg, 14, 255), -- Text14 sp +lit_multibyte(msg, 15, 255), -- Text15 split_multibyt +e(msg, 16, 255) -- Text16 );end_yvs_kj_ convert_severity_yvs_kj_ create or replace procedure convert_severity (IN omnibus_severity INTEGER, OUT tec_severity INTEGER) BEGIN if (omnibus_severity = 5) then set tec_severity = 50 elseif (omnibus_severity = 4) then set tec_severity = 40 elseif (omnibus_severity = 3) then set tec_severity = 40 elseif (omnibus_severity = 2) then set tec_severity = 30 elseif (omnibus_severity = 1) then set tec_severity = 10 else set tec_severity = 10 end if; END_yvs_kj_
      HI Keerthi can u help me to this Scenario , I am Having Virtual pair 1 and Virtual pair 2 In Virtaul pair 1 NCOMS PRIM two bi-directional gateway is installed one is for NCOMS to DCOMS and other is for Virtual pair 1 to virtual pair two DCOMS Backup Virtual pair 2 BCOMS PRI one BI-directional gateway is installed for Pri and Backup CCOMS BACKUP I hope successfully integerating everything Scenario is ,if NCOMS Primary(Server,ex:LINUX) is crashed the connection between Virtual pair 1 to Virtual pair 2 will be disabled so , I am installing 1 more bi-directional gateway in DCOMS Backup .For connecting Virtual pair 2.But it will be idle , When NCOMS Gateway Fails It has to be Initiate So that , I have to write the Script and include in Automation to start the Gateway . If u can Help me. my mailid is : 21vjkumar@gmail.com my number is +91-965019591 Please help me