Making a script that generates an output file dynamic

I've created the following script to run it from within SQL*Plus on my PC to generate a report regarding specific details about all my databases in one file. The idea is to get 1 result of all my databases.
Spool C:\output.txt;
-- start DB1
CONNECT system/pass@DB1;
COLUMN host_name format A18;
select * from v$database;
set line 380;
set pagesize 50;
select * from v$session order by username;
DISCONNECT;
-- end DB1
-- start DB2
CONNECT system/pass@DB2;
.......................same code as for DB1..................................
DISCONNECT;
-- end DB2
-- start DB3
CONNECT system/pass@DB3;
.......................same code as for DB1..................................
DISCONNECT;
-- end DB3
Spool off;
The above script, for instance, generates the name of the database and the sessions details of all my databases.
I have 40 DBs and they all have the same password for user system.
My question, is there a way to re-write this script to achieve the same thing but in a dynamic way. ie: the database connection string becomes dynamic, so that I write the code only once and if the code changes, I change it only one time instead of 40 times.
Notes: I'd like to run the script from SQL*Plus on my Window PC, I know that the same thing can be achieved by running a script on the DB server by using /etc/oratab, but actually these 40 DBs are on 10 different DB servers and there is no oratab used.
Many thanks for any tips,
Thomas

By awk on unix, or gawk or mawk on Windows (download http://www.klabaster.com/freeware.htm or ftp://garbo.uwasa.fi/pc/unix/gawk2156.zip) it's a easy task.
File select.sql (your query which you want run)
spool E:\Scripts\Sql\&1..log
select table_name from user_tables;
spool off
exitFile db.txt :
#col1 = ORACLE_HOME, col2=user, col3=pwd, col4=dbname, col5=script to run (cool if you run different scritps)
e:\oracle\ora92 scott tiger DEMO92 E:\Scripts\Sql\select.sql
e:\oracle\ora102 scott demo102 DEMO102 E:\Scripts\Sql\select.sqlFile select.awk (program calling by main prog)
{ print "set ORACLE_HOME="$1 }
{print "set ORACLE_SID=" $4}
{print "cd %ORACLE_HOME%"}
{print "cd bin"}
{print "sqlplus -s " $2"/"$3" @"$5" "$4}File run_select.cmd (the program which you will run)
gawk\gawk -f select.awk db.txt>run_select.cmd
run_select.cmdWell, now you have pfile and prog, you can work by simple enter name run_awk.cmd or scheduling by task windows :
E:\Scripts\Sql>run_awk.cmd    <-- you have finish your job, all lines after this one are automatic
E:\Scripts\Sql>gawk\gawk -f select.awk db.txt 1>run_select.cmd
E:\Scripts\Sql>run_select.cmd
E:\Scripts\Sql>set ORACLE_HOME=e:\oracle\ora92
E:\Scripts\Sql>set ORACLE_SID=DEMO92
E:\Scripts\Sql>cd e:\oracle\ora92
E:\oracle\ora92>cd bin
E:\oracle\ora92\bin>sqlplus -s scott/tiger @E:\Scripts\Sql\select.sql DEMO92
TABLE_NAME
A
BONUS
C
DEPT
EMP
HARSIMRAT
PLAN_TABLE
SALGRADE
T
T2
TAB1
11 rows selected.
E:\oracle\ora92\bin>set ORACLE_HOME=e:\oracle\ora102
E:\oracle\ora92\bin>set ORACLE_SID=DEMO102
E:\oracle\ora92\bin>cd e:\oracle\ora102
E:\oracle\ora102>cd bin
E:\oracle\ora102\BIN>sqlplus -s scott/demo102 @E:\Scripts\Sql\select.sql DEMO102
TABLE_NAME
DEPT
EMP
BONUS
SALGRADE
C
TAB1
TBL
MATRIX
TAB2
TAB3
TAB4
TABLE_NAME
TAB5
TEMP
TBL7
TBL6
IZZA
TBLA
TBLB
TBLC
TMP_LOOKUPS
TMP_HIER
TBL8
TABLE_NAME
TBL9
MV1
EMP2
THE_TABLE
26 rows selected.
E:\oracle\ora102\BIN>Two logfiles were generate DEMO92.log and DEMO102.log.
Now you can declinate this procedure to the infinity.
Nicolas.
Message was edited by:
N. Gasparotto
You have an alternative with mawk which seems more fast, command are same, just replace gawk by mawk.
Message was edited by:
N. Gasparotto

Similar Messages

  • Idoc types that generate the log files

    Hi All,
    Can anybody provide me the list of IDOC types that generated application log files.
    As I found that material master IDOCs generate log files. Is there IDOC types other
    than material master that generate log files.
    Regards,
    Azra.

    Hi Azra,
    You can tell whether an IDOC does create the application log from the function module it uses.
    Go to SE37, and type in IDOC_INPUT_<message_type> for inbound or IDOC_OUTPUT_<message_type> for outbound, and search for any function module which start with 'BAL_'. If you can find it, then it creates application log files.
    Regards,
    Lim...

  • Need a VB-Script that read a txt-file and only the lines that are new since last time

    Hi,
    I need help to write a VB script that read all new lines since the last time.
    For example:  The script reads the textfile at specific time, then 10 minutes later the script read the file again, and it should now only read the lines that are new since last time. Anyone that has such a script in your scriptingbox?
    cheers!
    DocHo
    Doc

    Based on the excellent idea by Pegasus, where is a VBScript solution. I use a separate file to save the last line count read from the file, then each time the file is read I update the line count. Only lines after the last count are output by the program:
    Option Explicit
    Dim strFile, objFSO, objFile, strCountFile, objCountFile, strLine, lngCount, lngLine
    Const ForReading = 1
    Const ForWriting = 2
    Const OpenAsASCII = 0
    Const CreateIfNotExist = True
    ' Specify input file to be read.
    strFile = "c:\Scripts\Example.log"
    ' Specify file with most recent line count.
    strCountFile = "c:\Scripts\Count.txt"
    ' Open the input file for reading.
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile(strFile, ForReading)
    ' Check if the line count file exists.
    If (objFSO.FileExists(strCountFile) = False) Then
        ' Initial count is 0, so all lines are read.
        lngCount = 0
    Else
        ' Open the line count file.
        Set objCountFile = objFSO.OpenTextFile(strCountFile, ForReading)
        ' Read the most recent line count.
        Do Until objCountFile.AtEndOfStream
            lngCount = CLng(objCountFile.ReadLine)
        Loop
    End If
    ' Read the input file.
    lngLine = 0
    Do Until objFile.AtEndOfStream
        ' Count lines.
        lngLine = lngLine + 1
        strLine = objFile.ReadLine
        If (lngLine >= lngCount) Then
            ' Output the line.
            Wscript.Echo strLine
        End If
    Loop
    ' Close all files.
    objFile.Close
    If (lngCount > 0) Then
        objCountFile.Close
    End If
    ' Ignore last line of the file if it is blank.
    If (strLine = "") Then
        lngLine = lngLine - 1
    End If
    ' Save the new line count.
    Set objCountFile = objFSO.OpenTextFile(strCountFile, _
        ForWriting, CreateIfNotExist, OpenAsASCII)
    objCountFile.WriteLine CStr(lngLine + 1)
    objCountFile.Close
    Richard Mueller - MVP Directory Services

  • A ksh script that generates a ksh script

    I am writing a ksh script to generate a ksh script. A snippet of the first script is shown below. The output that is generated is shown following that.
    First script:
    StartScript()
    echo $*
    StartScript log\(\)
    StartScript {
    StartScript 'echo $* >>$LOGGGGGGFILE'
    StartScript }
    This is the output that is produced:
    log()
    echo $LOGFILE
    $LOGGGGGGFILE}
    I can't figure out where the $LOGFILE is coming from....it should be $*. I've tried various permutations of quoting and backslashing, but nothing works.
    This is really strange, does anyone have any suggestions on how to do this?
    Thanks in advance
    Al

    The single or 'hard' quote around this line:
    StartScript 'echo $ >>$LOGGGGGGFILE'prevents the shell from interpreting the $ as a "value-of" operator. Use double quotes ("soft" quotes) and it should be fine.

  • Generate xml output file from relational table

    Hi All,
    I'd like to generate an XML file from a relational table but would like to persist the XSD in Oracle does anyone have a working example?
    Edited by: houchen on Jun 2, 2009 5:34 AM

    From the FAQ on the {forum:id=34} forum, {thread:id=416001}.
    If you are wanting to register the schemas in Oracle, you will find info on that as well in the FAQ.

  • How to Generate XML Output file

    Hi,
    I want to print sample output XML file.
    I got this link 362496.1
    An output file can be generated via the Preview functionality available under the XML Publisher Administrator responsibility. Navigation path :
    1. Login to the application as SYSADMIN
    2. Responsibility: XML Publisher Administrator
    3. Function: Templates
    4. Select a Template for which a Preview Data file has been uploaded in the past.
    5. Click on the Preview icon
    6. Save the PDF to the client PC
    7. Determine the version either by the above instructions OR by provide the PDF file to Global Customer Support.But in #4 I can not populate any values to search, even if I put all %.
    How can I get a valid search?
    Thanks a lot,
    Ms K

    Hi;
    AFAIK if you prepare template in XML publisher than you can take output as pdf, by the way you can take xml output too
    Please check user guide:
    http://www.oracle.com/technology/products/xml-publisher/docs/XMLP5.6.1UserGuide.pdf
    Oracle XML Publisher and Oracle Reports
    Oracle XML Publisher and Oracle Reports
    Also Please check below thread:
    XML output for pdf concurrent program
    http://www.quovera.com/whitepapers/downloads/xml_oracle.pdf
    Generate XML output using DBMS_XMLGEN.getxmltype and not from rdf
    http://www.orafaq.com/forum/t/35204/2/
    Hope it helps
    Regard
    Helios

  • Report Script - size of the output file

    I created a report script using the Hyperion Essbase Report Edit and saves the text in ASCII file. There is no error or warning message. If I checked the "Window" box under the "Report Output Options", the following warning message is displayed:

    I created a report script using the Hyperion Essbase Report Edit and saves the text in ASCII file. There is no error or warning message, even the "Show Warnings" box is checked.If I checked the "Window" and "File" boxes, the following warning message is displayed: "Output File is too large; truncating file"It looks like the warning is only for the report displayed on the screen. The data in the ASCII file is not truncated. Is this correct?

  • Dtrace Script to Generate List of Files that Changed on NFS server?

    Our Solaris NFS (v3/v4) fileserver serves filesystems with a huge number of files, a relatively few of which are modified daily. Is there a dtrace script I can run on the server which would generate a list of the files that were created or modified while it was running?

    Well, write something based on the rwsnoop from dtracetoolkit
    http://www.dtracebook.com/index.php/File_System:rwsnoop
    Then i guess we should ask ourself if its a good idea for a long term monitoring.. probably not.
    .7/M.

  • Create a FM that generates a PDF file.

    Hello Evryone.
    I have the following requirement.
    I need to create a function module that given a Personnel Number would generate the payslip for that person based on an existing SE51 form and return the payslip as a PDF file, so that it could be used in WebDynpro.
    Can any of you help me with this. How should I write this FM?
    Thanks a lot in advance.
    Francisco.

    HI Please refer the following code for converting a smartform into a PDF file
    DATA: BIN_FILESIZE TYPE I,
          BIN_FILE TYPE XSTRING,
         T_OTF  LIKE ITCOO OCCURS 200 WITH HEADER LINE,
          T_DOC  LIKE DOCS OCCURS 200 WITH HEADER LINE,
          T_LINES1 LIKE TLINE OCCURS 200 WITH HEADER LINE,
          T_FINAL_PDF LIKE TLINE OCCURS 500 WITH HEADER LINE,
    filename TYPE string VALUE 'EXP.pdf',
          path TYPE string VALUE 'C:\DESKTOP\..',
          fullpath     TYPE string VALUE 'C:\DESKTOP\PDF\EXP.pdf',
    CALL FUNCTION 'CONVERT_OTF_2_PDF'
      EXPORTING
        use_otf_mc_cmd               = 'X'
      ARCHIVE_INDEX                =
    IMPORTING
        bin_filesize                 = bin_filesize
    TABLES
        otf                          = t_otf
        doctab_archive               = t_doc
        lines                        = t_lines1
    EXCEPTIONS
       err_conv_not_possible        = 1
       err_otf_mc_noendmarker       = 2
       OTHERS                       = 3.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      LOOP AT t_lines1 INTO t_lines1.
           APPEND t_lines1 TO t_final_pdf.
      ENDLOOP.
      CALL METHOD cl_gui_frontend_services=>file_save_dialog
        EXPORTING
          default_file_name   = 'EXPO_INVpdf'
          prompt_on_overwrite = 'X'
        CHANGING
          filename            = filename
          path                = path
          fullpath            = fullpath.
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          bin_filesize = bin_filesize
          filename     = fullpath
          filetype     = 'BIN'
          append       = 'X'
        IMPORTING
          filelength   = bin_filesize
        TABLES
          data_tab     = t_final_pdf.
      IF sy-subrc EQ 0.
        MESSAGE s018(zmsg) WITH 'PDF Generated Successfully'.
      ELSE.
        MESSAGE s011(zmsg) WITH 'PDF Not Generated !!!'.
      ENDIF.

  • EEM script that generates only 1 email when a fxs port is offhook.

    Using the below config I am able to receive a email anytime my voice port is in any other state than ON HOOK. The problem I have is the script runs every 30 seconds and I receive an email every 30 seconds the line is in any other state than "ON-HOOK". 
    Is there a way to have only one email generated ONLY when the state changes from the previous state? 
    example : the line is on-hook, changes to off-hook or park or whatever- a email would be generated.  ( only One email). not one every 30 seconds...
                   The line goes from Off-Hook back to IDLE.  - A email would be generated to advise the line has been restored to a IDLE state. 
        I know what you're  thinking why? Well I was thinking of using the analog ports as kind of a poor man's slightly intelligent surveillance system. If port 1/0/0 goes off hook or shorted, then this is an alarm condition. A email would be generated. I just don't need a email every 30 seconds.  
    scheduler allocate 20000 1000
    event manager environment _email_from [email protected]
    event manager environment _email_to email [email protected]
    event manager environment _email_server smtp-server.isp.net
    event manager applet check_1/0/0_if_NOT_ONHOOK
     event timer watchdog time 30
     action 001 cli command "enable"
     action 002 cli command "show voice port summ | include 1/0/0"
     action 003 foreach line "$_cli_result" "\n"
     action 004  regexp "on-hook" "$line"
     action 005  if $_regexp_result eq "1"
     action 006   exit 0
     action 007  end
     action 008 end
     action 009 syslog msg "PORT_1_is_in_any_other_state_then_on-HooK!"
     action 1.0 mail server "$_email_server" to "$_email_to" from "$_email_from" subject "$_event_pub_time:Test EEM port 1/0/0 is SHORTED ie IN ALARM" body "TEST Body"
    end
    Any ideas?

    Look at EEM context to save the value of a variable across policy runs.  So you could retrieve the value of the context and compare it to the current value, if they are different then send an email and if they are the same then no action.
    http://www.cisco.com/c/en/us/td/docs/ios-xml/ios/eem/command/eem-cr-book/eem-cr-a1.html#wp2399063000
    The first time your updated policy runs and executes the context retrieve there will not be a value since you have to do a context save first.   To get around this make a second policy that runs at reboot to do a context save of the "on-hook" state.

  • How to delete duplicate data that generated from csv file??

    The thing i have done is that i red all the data in the csv file without removing the duplicate data and display it.. For where i should have a known number of index (about 13), my main file should have 13 records no duplicate values. and how can my Java program update the corresponding record in the main file each time an index is updated??
    Hope somebody can assist me on this..it would be really helpful for me...
    Thank you.
    -Rao-
    Edited by: reemarao on Apr 1, 2010 3:58 AM

    Hi Sudhir,
    In case you have edit access in your system carry out the following procedure:
    1. Create an export datasource on your cube.
    2. Now create the update rules to your cube using the datamart Infosource.
    3. In the update rules multiply all the key figures by
    -1.
    4. Now create an infopackage and give the request id of the duplicate request as selection.
    5. Load the datamart request and do the data validation.
    If you do not ahve edit access there is no other alternative you would have to delete all the data and reconstruct the requests that you need.
    Bye
    Dinesh

  • Create a script that can create entire schema with data when run

    Hi,
    I need to create a script that creates the entire schema on a database when the script is run. the need is that the script should be capable of creating all schema objects with grants and all, including the table data.
    The same objective can be achived through export / import.But we don't want to deliver the dump files instead a script which will be executed on a database created with same database stucture of tablespaces etc.
    I have serched the net but yet to achive the goal.
    Is there any oracle utility / script file that can do this for me ?
    Can Oracle import be used to create the same, the way it is used to create index File ?
    Please suggest !!
    Regards

    You should look at the package dbms_metadata to be able to extract all ddl to recreate a schema. To load the data, you could write scripts that will generate insert statements and spool these to a file (sql generating sql), or you could write scripts that generates a delimited file and use sql loader to load the data into the target system. There are lots of little gotchas in either of these 2 solutions. The biggest 2 right away. 1 - picking a delimiter, 2 - dealing with carriage returns in text data. SQL Developer is able to do some extraction, so before you go writing this stuff yourself, I would check it out to see if it does what you are looking for before you reinvent the wheel.

  • Output File not generated

    Hi All,
    I am using the Report Builder 10.1.2.0.2  on windows 7 Professional version ( 32-bits) , I am connecting to data base, compliing and Running the Report for paper layout it gives me the preview but when I am trying to generate the output file(either format) then no output file is created.
    it is not showing any error message either. what may be the reason ?
    Thanks in Advance.

    Rajan
    What I understand from your saying is:
    With a program R/3 is generating a File. So here there is no XI role.
    Then XI is picking this file and sending to FTP server. So File-XI-File scenario. First of all are you sure that your R/3 is generating the file what XI is expecting? If yes then your XI will pick up and you will see in SXMB_MONI. If not first find out whether it is generating or not. If it generates and if you are unable to pick the file then check the authorisations. Also if you are doing Content conversion kindly go to adapter monitor and find out whether you can see any error?
    Regards,
    ---Satish

  • ALV Grid to be run in background & to generate output file in Excel format

    I use  REUSE_ALV_GRID_DISPLAY in my program for the ALV output
    My Requirement is Program to be run in a background since it is getting timed out when executed in foreground and also to generate the output file in Excel format. And we are using 4.6 C version.
    how do i attain this?

    Hello,
    One alternate solution can be :
    Execute your report in background and then send the data to Spool .
    From this spool , you can download the data in excel file.
              SUBMIT xyz TO SAP-SPOOL
                 SPOOL PARAMETERS gt_print_parameters.
    Regards,
    Sandeep

  • How to generate output file of a certain report in a specified directory

    Hello everyone,
    I wanna know how to generate the output file of a certain report in a specified directory.
    Now, the output file directory = /produits/OA/OAS/production/prodcomn/admin/out/PROD_us15k1bp/
    I wanna to generate the output file of a report in this directory
    /produits/OA/OAS/production/prodcomn/admin/out/PROD_us15k1bp/FACTCLIENT
    Cause the output of this report is very large, so I don't wanna to put it in the output drectory standard which reduce the performance.
    Could you help me?
    Thanks a lot,
    Kinkichin

    Hi,
    I wanna know how to generate the output file of a certain report in a specified directory.See (Note: 158088.1 - Is Possible to Redirect the Concurrent Processes Output to a Specific Directory for a Specific Responsibility?).
    Cause the output of this report is very large, so I don't wanna to put it in the output drectory standard which reduce the performance.There should be no performance issues you place the output file in the same directory where other concurrent request output files are located.
    Regards,
    Hussein

Maybe you are looking for

  • Moving iphoto videos from mac to pc

    i have searched for nearly a week now about this topic. i am trying to move my photos and videos from iphoto to pc via an external hard drive. i can do this, and the pictures show up, but the videos will not play. i've tried opening them with quickti

  • Open document format

    I'm not sure if this is the appropriate category to place this question, but is there a way we can de-couple the open document plugin for abiword from the gnome libraries? It seems vastly inappropriate to require gnome for this plugin, considering th

  • Oracle portal vs php

    could you give me about comparation web development using oracle portal and php. how about speed, security, flexibility ? where i can find, site with oracle portal ?

  • QuickTime 7.1.5. and OSXPlanet

    Like many others here I experience formerly unkown problems with QT. After downloading the new QT 7.1.5. one of my most beloved programs, OSXPlanet, does not show any desktop screen nor picture more. I tried everything – removed all the OSXPlanet fil

  • Can't login App Store

    I have the same problem that other people: " The Apple ID you entered couldn't be found or your password was incorrect. Please try again." The problem is in iphone, pc no problem, web no proble, itunes no problem. I restores iphone, get app in itunes