Can I just issue sqlplus command like a Korn shell does in python?

Hi
I have a question on python as an Oracle DBA. Do I have to have cx_oracle or another similar compenent in order to access Orade database? Can I just do sqlplus like a Korn shell does?
I am an Oracle DBA. Daily job requires shell scripting. I am skilful at Korn/BASH which I use on a daily basis to interact with database. However, I found them not powerful and flexible enough to handle text and strings. I am new to both Perl and Python. I pick Python because it is easy to read and maintain. Learning curve is not as steep as Perl.
I am not a developer who cares much about data types compatability or APIs. I do care about how to pass Unix variables in Python. A typical task is like
=================================================
set Unix environment variables (each database has a line in a file)
use sqlplus to connect to each database specified in the file, i.e. looping
get information I want and store them in files, i.e. logs
end loop
do text/string manipulation againt the log file
if error is found, send email alert to DBA
=================================================
Thanks,
Kevin

Kevin,
Python has some great libraries to do what you are asking in the Unix enviornment:
To get enviornmental variables:
====================
import os
# store the env var audit_username in a variable; if it doesn't exist, use 'davew' as the default
username = os.getenv("audit_username",default='davew')
To run Unix commands:
====================
import commands
# run a command from unix (example from Python manual
commands.getstatusoutput('ls /bin/ls')
Dave Warner

Similar Messages

  • How to execute sqlplus command like 'show parameters '  in SQL Developer?

    Hi guys,
    here's another problem i just ran into, is it possible to run sqlplus cmd like 'show parameters ' in this tool? anyone can help? thanks in advance.

    thanks.
    and i just looked into the user guide and found that several sqlplus commands were unsupported in SQL Developer, including 'show '. i don't know why but anyway i get the answer, i can go back to use sqlplus itself.

  • Can I just use the contact like a normal phone on I Phone by not using I Cloud

    I have a problem loosing the contacts that was recently installed in Contacts. How can I use the I Phone like a regular cell phone where I can keep my contacts forever without needing I Cloud or any new stuff

    babamaymay wrote:
    I have a problem loosing the contacts that was recently installed in Contacts. How can I use the I Phone like a regular cell phone where I can keep my contacts forever without needing I Cloud or any new stuff
    Just add them on the iPhone like a regular cell phone.

  • HT5891 how do I clear all the apps so I can see just the desktop background like in Snow Leopard all those years ago?

    I used to just be able to three finger swipe up!

    Sorry I wasn't quite clear,
    I meant that in order to see what I have on my desktop like on startup before I use any apps, I just want to hide any apps that are running without having to actually close any. Say for example I want to open a document or movie that I know is on my desktop I could just swipe up on Snow Leopard and see them, but I don't know how to do this on Mavericks.

  • How can I import all of my bookmarks and not just some of the like the import tab does?

    I tried to import my bookmarks but it took only a few bookmarks and left most of my list behind. I tried the import from IE many times and get the same result so how can I get all my bookmarks moved over?

    If you have problems with importing the IE Favorites in Firefox then export the favorites in IE to an HTML file and import that file in the Firefox Bookmarks Manager.
    If you do not have the menu bar in IE then right-click the toolbar at the top to enable the Menu Bar.
    * Export the favorites in IE to an HTML file (bookmarks.html):<br>File > Import and Export
    * Import the HTML file in Firefox:<br>Bookmarks > Show All Bookmarks > Import & Backup > Import Bookmarks from HTML: From File
    See "Import from another browser" and "Import from file":
    * http://kb.mozillazine.org/Import_bookmarks

  • HT1386 I HAVE COPIED ABOUT 2.5OO PHOTOS FROM MY PC TO MY NEW iPAD. I REPEATED IT SEVERAL TIME BUT EACH TIME I CAN SEE JUST A FEW PHOTOS COPIED, WHAT AM I DOING WRONG????

    BY THE WAY, I CAN SEND EMAIL MESSAGE FROM MY NEW iPad to any private - personal emails using as sender the firts of my given email addresses (one from the gmail.com) - IN THOSE EMAILS I CAN SEND A PHOTO BUT I CANNOT DO THE SAME TO THE FaceBook EVEN WHEN USING THE UNIQUE EMAIL ADDRESS THAT FACEBOOK GAVE ME TO SEND PHOTOS BY MOBILE PHONE, CAN SOME ONE OF YOU SHOW ME THE WAY TO SEND AT LEAST PHOTOS TO THE FACE BOOK VIA THE NEW ipad purchased recently. SO FAR (I HAVE GOT THE NEW ipad) I HAVE NOT TRIED TO SEND VIDEOS TO BOTH FACEBOOK AND YOUTUTE. I WOULD WELCOME ANY SUGGESTION OR HELP FROM ANYONE OF YOU, HAVE A GREAT TIME ALL OF YOUR FROM ATHENS, GREECE

    Have you tried deleting the photo cache from your computer and then re-trying the photo sync and see if they all then copy over (you need to select and sync all the photos that you want on the iPad together in one go, as only the most recent photo sync remains on the iPad) ? The location of the cache, and how to delete it, is on this page http://support.apple.com/kb/TS1314
    Don't know about the Facebook photo emailing, but there are a number of apps that allow to upload photos to their site (e.g. the 'official' Facebook app).
    (For future info, typing all in capitals is considered SHOUTING - you are more likely to get help/responses if you don't.)

  • Command Line Recall (Korn Shell) - Last Command Not Blank

    I'm using emacs for command line recall, so I use the up and down arrow keys, which work fine.
    However, I come from a Tru64 background, and when I go back through the commands, and then come forward again, I expect to be able to go past the last command entered and return to a blank command line, so if I don't want to choose anything from history I can enter a new command. What's happening for me on the Solaris box I am now working on is that going forward in history sticks on the last command entered, so I have to backspace it to enter anything new.
    Any ideas on how I can change this behaviour?

    Kevin,
    Python has some great libraries to do what you are asking in the Unix enviornment:
    To get enviornmental variables:
    ====================
    import os
    # store the env var audit_username in a variable; if it doesn't exist, use 'davew' as the default
    username = os.getenv("audit_username",default='davew')
    To run Unix commands:
    ====================
    import commands
    # run a command from unix (example from Python manual
    commands.getstatusoutput('ls /bin/ls')
    Dave Warner

  • Exec SQLPLUS command from PL/SQL Block

    Good Morning:
    How I can execute a SQLPLUS command (like SPOOL or DESCRIBE) from PL/SQL Block Procedure?:
    DECLARE
    BEGIN
    ls_command = 'DESCRIBE '||ls_table_name;
    EXECUTE SQLPLUS(ls_command);
    END;
    Thanks a lot for any idea.

    That's correct.
    However, in the case of the given example we can use DBMS_DESCRIBE package to get table descriptions. And we can use UTL_FILE to spool PL/SQL stuff to a file.
    Cheers, APC

  • [SOLVED] Long prompt delay after issuing a command

    I use VirtualBox to run archlinux.
    When I issue a command, like ls in a directory with many files, the long outcome on the screen ends relatively fast (2-5 sec) but the command prompt is only available after 20-30 sec. In the meantime, processor is still in heavily use (95-100%). As soon as the prompt becomes again available the processor use drops to normal level.
    Does it have to do with virtualbox or ...?
    Thanks
    Last edited by barcher (2010-12-16 20:33:49)

    I run Arch Linux in Virtualbox and yes its does take up quite a bit of system resouces
    Depends on your system specs, amount of ram given over to VM etc...
    But to answer your question yes it does have a lot to do with Virtualbox.
    Arch would of course run very very fast in a real sytem enviroment
    Welcome to Arch :-)

  • Can I issue this command in PL/SQL: EXECUTE IMMEDIATE '@filename.sql';

    can I issue this command in PL/SQL: EXECUTE IMMEDIATE '@filename.sql';

    Hi,
    Rather the opening a new process (sqlplus), a new connection (need password) etc... I would rather read and execute the file in pl/sql.
    I do not know if someone wrote it already, but here is a quick and dirty code for doing that with UTL_FILE.GET_LINE
    Here, I am only processing some DML statements and no SELECT statements. Correct it as you like !
    CREATE OR REPLACE PROCEDURE run_script ( dir_name IN VARCHAR2,file_name IN VARCHAR2)
    IS
    vSFile UTL_FILE.FILE_TYPE;
    vCmd VARCHAR2(200);
    vNewLine VARCHAR2(200);
    BEGIN
        vSFile := UTL_FILE.FOPEN(dir_name, file_name,'r');
        vCmd := NULL;
        IF UTL_FILE.IS_OPEN(vSFile) THEN
        LOOP
            BEGIN
                UTL_FILE.GET_LINE(vSFile, vNewLine);
                if (vCmd is null) THEN
                    if (upper(vNewLine) like 'INSERT%' or upper(vNewLine) like 'UPDATE%' or upper(vNewLine) like 'DELETE%') THEN
                        if (vNewLine like '%;') THEN
                            /* we have a single line command, execute it now */
                            dbms_output.put_line(substr(vNewLine,1, length(vNewLine)-1));
                            execute immediate substr(vNewLine,1, length(vNewLine)-1);
                        else
                            /* we have a command over multiple line, set vCmd */
                            vCmd := vNewLine;
                        end if;
                    else
                        /* ignore the rest like spool, prompt, accept, errors, host, @, ... */
                        null;
                    end if;
                else
                    if (vNewLine like '%;') THEN
                        /* we have a the last line of the command, execute it now */
                        vCmd := vCmd || ' ' || substr(vNewLine,1, length(vNewLine)-1);
                        dbms_output.put_line(vCmd);
                        execute immediate vCmd;
                        vCmd := null;
                    else
                        /* keep concatenating to vCmd */
                        vCmd := vCmd ||' '|| vNewLine;
                    end if;
                end if;
            EXCEPTION
                WHEN NO_DATA_FOUND THEN
                    EXIT;
                END;
        END LOOP;
        COMMIT;
        END IF;
        UTL_FILE.FCLOSE(vSFile);
    EXCEPTION
        WHEN utl_file.invalid_path THEN
            RAISE_APPLICATION_ERROR (-20052, 'Invalid File Location');
        WHEN utl_file.read_error THEN
            RAISE_APPLICATION_ERROR (-20055, 'Read Error');
        WHEN others THEN
            RAISE_APPLICATION_ERROR (-20099, 'Unknown Error');
    END run_script;
    set serverout on
    create directory scriptdir as '/home/oracle';
    grant read,write on directory to scott;
    exec run_script('SCRIPTDIR', 'test.sql')

  • My iMac keeps on losing internet connection. Webpages get stuck after a minute or so. If I check the internet connection via diagnostics it seems to work just fine. Others, like the iPad use the same wifi connection and never fail. What can I do?

    Running 10.6.8 on Intel dual core iMac, it keeps on losing internet connection. Webpages get stuck after a minute or so. If I check the internet connection via diagnostics it seems to work just fine. Others, like the iPad use the same wifi connection and never fail. What can I do?

    Greetings,
    I've never seen this issue, and I handle many iPads, of all versions. WiFi issues are generally local to the WiFi router - they are not all of the same quality, range, immunity to interference, etc. You have distance, building construction, and the biggie - interference.
    At home, I use Apple routers, and have no issues with any of my WiFi enabled devices, computers, mobile devices, etc - even the lowly PeeCees. I have locations where I have Juniper Networks, as well as Aruba, and a few Netgears - all of them work as they should.
    The cheaper routers, Linksys, D-Link, Seimens home units, and many other no name devices have caused issues of various kinds, and even connectivity.
    I have no idea what Starbucks uses, but I always have a good connection, and I go there nearly every morning and get some work done, as well as play.
    You could try changing channels, 2.4 to 5 Gigs, changing locations of the router. I have had to do all of these at one time or another over the many years that I have been a Network Engineer.
    Good Luck - Cheers,
    M.

  • I just updated my pages and now it won't load. This is on my iPad. The first version which has the latest version it can have 5.1 or something like that. I am trying to open a document and am worried that if I uninstall and reinstall I will lose all my do

    I just updated my pages and now it won't load. This is on my iPad. The first version which has the latest version it can have 5.1 or something like that. I am trying to open a document and am worried that if I uninstall and reinstall I will lose all my documents

    I just uninstalled it and am waiting for it to reinstall. I sincerely hope that I have not lost everything that I worked on so hard. Now that mobile me is gone, I have not been able to go between devices to transfer things. I was merely trying to take a document I had worked on and open it in pages, but it said my version was too old. When I updated, it wouldn't load. Now I cannot do anything. I hope that the reinstall fixes it without losing everything. Please advise!!! Yes, I am in panic mode.

  • I bought a relative's original iPad. I want to leave the apps on it and add my own pdfs to read. My itunes account is really for my iPod. the computer says that if I "Sync" the iPad will be erase, and become like my iPods. how can I just get my files onto

    I am a first-time iPad owner/user. I bought a relative's original iPad. I want to leave the apps on it and add my own pdfs to read. My itunes account is really for my iPod. iTunes message says that if I "Sync" the iPad will be erase, and become like my iPods. If I make a new iTunes account, would the apps be erased when I tried to use it?
    How can I just get my files onto this iPad, and still have the apps that my relative left there for me?
    Thank you.

    iPads sync to 1 computer only.
    All media and apps are tied to the Apple ID that purchased them.
    Without your relatives ID and password, you cannot update any of the Apps.
    I am pretty certain he is also violating Apples terms of service by giving you the apps.

  • Hi Can anyone please tell me from where I cn download the Photoshop CS6 program I purchased a download (media less) some 2 years ago and all has been OK up to know but I am know having issues and would like to uninstall and reinstall. I have the revelant

    Hi Can anyone please tell me from where I can download the Photoshop CS6 program I purchased a download (media less) some 2 years ago and all has been OK up to know but I am know having issues and would like to uninstall and reinstall. I have the relevant codes and activation keys but would need to be sure I can obtain the program again before I start. Thank you

    Make sure you are dealing with the correct product for the serial number.  If the serial number is for a full creative suite then you need to get the suite, not the individual application, and vice versa.
    Unrelated to that, in case it helps, here is a link to another site.  You can download the trial version of the software thru the page linked below and then use your current serial number to activate it.
    Be sure to follow the steps outlined in the Note: Very Important Instructions section on the download pages at this site and have cookies enabled in your browser or else the download will not work properly.
    CS6: http://prodesigntools.com/adobe-cs6-direct-download-links.html

  • Can anyone help with Double Command issues. This a specific keyboard question and they do not seem to know.

    Before I go into a lengthy explanation of the problem: Can anyone help with Double Command issues. This a specific keyboard question and they do not seem to know.
    Thanks much.
    Emile

    Choose Force Quit from the Apple menu and close Mail from there.
    (103661)

Maybe you are looking for

  • Crashes every time i try to play in full screen and share

    Error Report reads Process:     iMovie [351] Path:        /Applications/iMovie.app/Contents/MacOS/iMovie Identifier:  com.apple.iMovie8 Version:     8.0.6 (821) Build Info:  iMovieApp-8210000~16 Code Type:   X86 (Native) Parent Process:  launchd [136

  • Removing dupes in iPhoto

    I"ve had a look through other questions about this issue, but I'm still a little unclear about this.  I've never re-imported my iphoto library and the pictures I tend to import are synced directly from my iPhone 4.  I do keep around 300 images on my

  • System log query is flooded with the message.. WindowServer[]: WSSetTrackingAreaEnabled : Invalid tracking area

    Hello apple community (: quick question my system log query is flooded with the message.. "8/29/14 12:10:12.258 PM WindowServer[176]: WSSetTrackingAreaEnabled : Invalid tracking area 0x61000089f220" it has shown me after i run Mavericks Cache Cleaner

  • Notepad Plain Text Equivalent for html files

    Hi I want to open an html file to see the source - in windows I would right (context) click and open with notepad. What is the equivalent in Mac - when I try textedit it opens it in RTF and so I can't see the underlying markup. Thanks

  • Using my spanish imac in US

    Hi guys, I hope anyone of you can help me. I´m moving to the US and I would like to know if using my imac bought in Spain will be possible in the States because of the different intensity. In Spain are 220 V and in the States I think it is 110 V. Do