Shell script abort execution if script hangs

I have a shell script that runs every minute and runs a script against the db. Like this …
sqlplus user/pass << EOF
@@myscript.sql
exit;
EOF
There is a possibility that my script may hang and I dnt want a hanging process on linux server as this may build up every minute and kill the server. How can I set my script to terminal if it can’t execute myscript.sql after 5 minutes?
Thank you!

sybrand_b wrote:
Just delete the script and replace it by a stored procedure which runs through dbms_job or dbms_scheduler.
We are in the 21st century. Not in 1973.
Sybrand Bakker
Senior Oracle DBAsorry not very good with plsql ,is it possible to do it in shell script? :)

Similar Messages

  • Error Handling with sql *plus from a shell script

    When I execute sql plus in a shell script with the wrong username/pass pair, the shell script hangs without terminating. What is the proper way to execute sql plus in a shell script that will catch a login failure and make sure the script doesn't hang?
    Example:
    We execute the following in our shell script:
    sqlplus ${ORACLE_INST} @./sql/ftp_ledger_put.sql
    Now if somebody comes along and alters the login then the script would hang. Is there a way to have the script exit gracefully?

    Not the most elegant solution but.......
    sqlplus &lt;&lt;EOD 2&gt;&1 &gt;some_log_file
    user/pwd
    @somescript
    exit
    EOD
    Because sqlplus allows for 3 tries at log in if user/pwd is not valid it will try to use subsequent lines. Each will fail.
    You have to look in some_log_file to determine success/failure
    Ken

  • Error with dbms_scheduler and shell script execution

    Hi,guys.
    I have an issue with a dbms_scheduler and a shell script execution. So, the shell script as it self works fine, when i'm executing ./test.sh all process is running, but when i'm executing the script from dbms_scheduler it just simply doesn't work. Actually it works, but some of executable information in sh doesn't work, seems it just jump over of the part of the script. Sendmail part is running, maybe there is problem with rman script as it self?
    DB version: 10g
    And my scripts:
    Shell scripts (permisons 755):
    #!/bin/ksh
    export PATH=/home/oracle/product/asm_home/bin:/home/oracle/product/db_home/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/home/oracle/bin:/usr/bin/X11:/sbin:.
    export ORACLE_BASE=/home/oracle/product
    export ORACLE_SID=zabbix
    export ORACLE_HOME=/home/oracle/product/db_home
    ${ORACLE_HOME}/bin/rman<<EOF
    connect target /
    run {backup recovery area delete all input;}
    EOF
    {       echo "From:[email protected]"
            echo "To: [email protected]"
            echo "Subject: Recovery area"
            echo 'Content-Type: text/html'
            echo
            echo '<html><body><table border="1" cellspacing="1">'
            echo '<tr><td><b>Process</b></td><td><b>Statuss</b></td></tr>'
            echo "<tr><td>RMAN</td><td><b>Works</b></td></tr>"
            echo "</table></body></html>"
    } | sendmail -tIn the first part i'm exporting all of the important stuff for oracle, then I call RMAN with specific atributes. And then there is just simply sendmail functionality inside script to represent if script works (for now).
    And below pl/sql script:
    begin
      DBMS_SCHEDULER.CREATE_JOB
      job_name => 'FLASH_RECOVERY',
      job_type => 'EXECUTABLE',
      job_action => '/home/oracle/backup/test.sh',
      start_date => sysdate,
      job_class => 'DEFAULT_JOB_CLASS',
      enabled => TRUE,
      auto_drop => FALSE,
      comments => 'FLASH RECOVERY USAGE AREA backup and delete'
      END;
      /And this job execution:
           begin
               DBMS_SCHEDULER.run_job (job_name =>'FLASH_RECOVERY',use_current_session => TRUE);
           end;What can be wrong? For me, I think it's something with permisions.
    I hope you got my idea and could help me.
    Tom
    Edited by: safazaurs on 2013.18.2 22:16

    There is no error, i just receive all the time e-mail, seems it jumps over rman. I tried almost everything and still couldn't get result as i want. And, if i'm running script from command line - it works. Rman calls, and starts to recover archivelogs.

  • Help 'Exiting' after Automator Shell Script Execution

    Hello,
    I've recently installed and got running GCalDaemon (http://gcaldaemon.sourceforge.net/) which allows me to Synch Rainlendar <-> Google Calendar through iCal (You can also synch iCal <-> Google Calendar). I needed to start up a shell script/applescript after each startup/login in order for GCalDaemon to start the synching process each time and continue to do so at the timed intervals. I would do so by the following terminal code:
    cd /usr/local/sbin/GCALDaemon/bin
    ./standalone-start.sh
    I then tried automating this process and came across shell script execution through Automator. I did so and created a .app with the above mentioned code. This works and it starts up the necessary .sh file I need and the snyching works under StartUp. My concern is however, how do I exit terminal once the code has executed the necessary file? All I have in my .app is the above mentioned code for now. I just need it to exit terminal because on startup or after starting the program, I get this issue (See Attachment)
    This continues to run, so my guess is that I need to add code to exit terminal and allow the .app to close itself properly after doing so.
    Please guide me in the right direction.
    Picture Belows shows what happens when I run the Automator App. It continues to run until I quit out of the app manually (TheGCal programs works fine though). I feel I need to have app quit Terminal or fully end the process and quit out on it's own.
    Thanks
    <table style="width:auto;"><tr><td></td></tr><tr><td style="font-family:arial,sans-serif; font-size:11px; text-align:right">From GCalDaemon</td></tr></table>

    i redirected the command output to /dev/null which is unix equivalent of a black hole and I also redirected error output to standard output in case the script produces any errors.
    also & at the end tells it to continue without waiting for the script to finish.
    Message was edited by: V.K.

  • The Shell script keeps hanging

    Hello,
    I have the following shell script and when i execute, it keeps hanging and nothing happens
    Please let me know.
    Requirement is to read data from file and pass it to the sql and create files as shown.
    code
    #!/bin/sh
    while read user.dat
    do
    echo "user = $1 email = $2"
    done
    sqlplus -S /NOLOG << EOF
    connect username/pwd@schema
    select user_name,count(*) from apps.fnd_user
    where 1=1 and user_name ('$1') and email_address ('$2')
    group by user_name;
    EOF
    if [ $? -ne 0 ]
    then
    % cat > user_exist
    else
    % cat > user_notexist
    fi
    exit 0
    Data File
    rsreenivasa null

    Well, youy have many problems here:
    while read user.dat
    do
    echo "user = $1 email = $2"
    done
    The "user.dat" string is an invalid variable name, so this loop never runs.
    Then, in this sequence:
    if  $? -ne 0
    then
    *% cat > user_exist*
    else
    *% cat > user_notexist*
    fi
    The cat(1) commands then copy stdin to either "user_exist" or "user_notexist".
    You don't show how you run this command, so we cannot tell what happens exactly.
    Please delete everything below the "while read ..." loop. Get that loop working as you expect it should. Then add a few more lines and test those. Build the shell script incrementally, debugging each as you go.
    Hint: since this is a shell script, run it like this:
    $ sh -x ./myscript arg1 arg2 ...
    to see what happens as it happens.
    Cheers

  • Shell script execution from stored procedure

    I am working on a project thallt requires a shell script be executed upon the execution of a stored procedure with Oracle 10g. I have researched the matter, but there does not seem to be much out there on how to execute lines of UNIX commands by use of a stored procedure. If anybody has ever gotten this to work, any information would be appreciated. If the task is impossible, let me know, I just could not confirm that it was not something that could be done.

    A combination of things can help you out here - none of which are easy or particularily secure.
    1) From plain PL/SQL, you can call 'external procedures'. That is basically a DLL or .so that the listener can load on demand, and that external procedure (EXTPROC) can run whatever you need from the C program. C can, in turn, call a shell.
    This is fairly well documented, but be aware that 1/2 of the info is in the PL/SQL docco and the other half in the Networking docco.
    A fair bit of info is available in metalink as well - if you have access, simply search on extproc.
    2) You can call a Java stored procedure which in turn has hooks to the outside world. That will probably require a PL/SQL to Java wrapper to make it available in your environment. Oracle has been using this one successfully for a while.
    3) Write the script using UTL_FILE and have a daemon look for, and execute, the script.
    4) Since you are using 10g, use the new job scheduler. It has excellent capability to interact with the OS, and it is available as a PL/SQL package (DBMS_SCHEDULER). I find the interface a bit heavy, but that could be wrapped by a library tailored to your specific needs.
    Let us know what you decide to do in the end (and why) - it is an interesting topic.

  • Why execution status of stored procedure in shell script is returning same?

    Hi Friends,
    My shell script has below code to execute Pl/Sql procedure.depending on pl/sql procedure status i need to execute the script further.
    i am testing error condition.So i kept exe instead of exec for executing procedure.it suppose to return non zero.But iam not getting the correct status in shell script using $?.
    even for error condition also status is returning zero(0).How to catch execution status of stored procedure in shell script?
    can you please me suggest whats is wrong in below code?
    echo "*************************************************************"
    echo "             cleaning replica tables"
    echo "*************************************************************"
    sqlplus -s migrat/****@dotis01<<ENDOFSQL
    WHENEVER SQLERROR EXIT 1;
    exe PKG_OTU_HELPER.SP_CLEANUPREPLICA;
    Commit;
    exit;
    ENDOFSQL
    status=$?
    echo $status // showing 0 always.
    +if [ $status -ne 0 ]+
    then
    echo "issues in cleaning in replica tables"
    exit;
    fi
    +#Loading of data from flat files to migration tables using sqlldr programs+
    echo "*************************************************************"
    echo "      Loading of data from flat files to migration tables"
    echo "*************************************************************"
    sh /opt/finaclesoftware/UBS_10.4.02_AIX/AIX/DB/CRM/Oracle/OTU/Retail/ControlFiles/LoadData1.com
    Thanks,
    Venkat Vadlamudi

    The whenever sqlerror clause is a sqlplus command. When Oracle (that is, the sql engine of the pl/sql engine) raises and error in a sql statement, the whenever sqlerror command determines what happens.
    Exec is also a sqlplus command, exec <procedure> is shorthand for begin <procedure> end;, that is, it creates an anonymous block.
    Your misspelling of exec as exe is not an Oracle error, it is a sqlplus error. The command never actually gets to Oracle, so there has not been a sqlerror for whenever sqlerror to respons to.
    Consider, I do not have a procedure called p
    SQL> desc p
    ERROR:
    ORA-04043: object p does not existI try to call it with exe as in your code:
    SQL> exe p;
    SP2-0042: unknown command "exe p" - rest of line ignored.Note the error message is form sqlplus (SP2).
    But, if I call it correctly usinf exec:
    SQL> exec p;
    BEGIN p; END;
    ERROR at line 1:
    ORA-06550: line 1, column 7:
    PLS-00201: identifier 'P' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignorednow I have a sql error, and whenever sqlerror exit 1 would quit sqlplus with a return value of 1.
    John

  • Logging OWB mapping execution in Shell script

    Hi,
    I am executing a OWB mapping from a shell script like this
    $OWB_SQLPLUS MY_WAREHOUSE plsql MY_MAPPING "," ","
    I want to log this mapping execution process into a file.
    Please let me know if this will work:
    $OWB_SQLPLUS MY_WAREHOUSE plsql MY_MAPPING "," "," >> LOGFIL.log
    I will just be using this log file to track all the execution and use it for logging purpose.
    If this wont work, please tell me the proper way to do this...
    Thanks.

    Avatar,
    ">>" is the Unix operator that will redirect output and append to a particular file, so what you have should work if you're executing it from the shell prompt. Although I don't know specifically what OWB_SQLPLUS and MY_WAREHOUSE are.
    In my company, we have the call to the owb script inside another script. For example, file x contains the following line:
    sqlplus repository_user/pwd@database @sqlplus_exec_template.sql repository_owner location task_type task_name custom_params system_params
    Then at the prompt, we enter:
    nohup x > x.log &
    And the mapping or workflow executes.
    Jakdwh,
    Are you redirecting your output to a file so you can see why it's returning a '3'? The log file will usually tell you where the error occurred. I don't know what your input parameters for your mapping is, but the script is pretty picky about the date format. Also, even if you don't have any input parameters, the "," still has to be sent into the script.
    Hope this helps,
    Heather

  • Shell Script: Timeout and return error if Sqlplus hangs

    Shell Script: Timeout and return error if Sqlplus hangs
    Dear all,
    This morning, our production database hung with lots of ORA-600 and 7445. The issue has been escalated to Oracle Tech support but my monitoring script which tries to make a connection every 5 mins to the database to see if its up, did not alert me. The reason is that, it connected to the database and hung, never came out to report an error and so I never got alerted until a user called me.
    Can any one tell me how I can exit from the sqlplus block if I dont get a response in x seconds? This sqlplus block is being called with in a shell script.
    Any help is highly apprciated.

    I don't know of anything built into any shell scripting language that would do this, no. I'm not a Perl programmer, but I have a vague recollection that Perl may have something useful here.
    From the "separate thread" part of my comment, though, you could certainly spawn a separate thread (thread 2), have thread 2 wait a period of time, then look for a message from thread 1 and throw an error if the message hadn't been sent. I don't know that I'd be for writing multi-threaded shell scripts, though. The heartbeat also gives you a layer of redundancy so that something is monitoring the monitor in case that process stops working.
    Justin

  • Controlling a procedure execution from a UNIX shell script

    I want to control the execution of a PL/SQL procedure from a UNIX shell script.
    Below, I include the script.
    The control variable which should recive the return of the procedure, dosen't work well.
    I want to control the return, because I wanr to make a UNIX script to control the execution of
    a load data process with some Oracle procedures.
    #!/bin/ksh
    echo "Executing procedure pl/sql"
    SQLPLUS="sqlplus -s /"
    ESQUEMA="esquema1"
    echo "\
    call ${ESQUEMA}.Z_PROC_PRUEBA();" | $SQLPLUS
    echo "Controlling pl/sql execution"
    var_err=$?
    if [ $var_err -gt 0 ]
    then
    echo "Error executing pl/sql"
    else
    echo "pl/sql finished sucessfully"
    fi

    This is not oracle problem. You can try something like this in your shell program ->
    DEV=Udev01/1ods@ODS1
    DEV_ID=`sqlplus -s ${DEV} <<!
             set heading off feedback off verify off
             set serveroutput on
             @/prod/ods/satyaki/prac/ctl_build.sql '$1' '$3';  -- If you sql needs to pass argument
             exit
             !`
    O_DIV_ID=`echo $DIV_ID | tr -s " " | sed 's/^[ ]//g'`
    if [[ $O_DIV_ID -ne 0 ]]; then
          echo "Successfully EXecuted.."
    else
      echo "Failed..."
    fiHope this will help.
    Regards.
    Satyaki De.

  • Stored Proc Execution through OS command using shell script

    Hi All,
    I have a requirement of executing one stored procedure before putting data in Table through JDBC adaptor and two stored procedures after that.
    I was thinking to write a shell script and execute it before and after message processing in adaptor.
    Can anybody please tell me how should i write a shell script for it?
    I have identified that exec <Stored_Proc_Name> is the syntax for it.
    Will i need to write something more in this script?
    Thanks,
    Atul

    Hi Atul,
    Stored procedures are written on the Database server for which you are going to write JDBC adapter.
    you will just call the storedprocedure in to your adapter.
    as per your requirement you shd run one stored procedure (let us say SP1) and then you have to push data into tables and then run SP2 and SP3...
    so for this write three stored procedures and call them into another SP. in this SP you call SP1 first then insert statement to insert data into tables and then SP2 and SP3.
    finally call SP into your JDBC adapter.
    you can call SP1 in SP as below
    Var_SQL :='call SP1 (''' || Var_1 || ''',''' || Var_2 ||''')' ;
    EXECUTE IMMEDIATE Var_SQL;
    i think for this shell script is not required.. correct me if i am wrong...
    Regards,
    Sukarna.

  • Speed up shell script execution

    Hi All,
    Before I go on, I must stress I am doing this for a disk image that I OWN, it's in no way an attempt to break into someone else's data...
    Last week I created an encrypted disk image (10GB) but have since forgotten the password stupidly!!!
    So, I figured I could knock up an applescript to try and brute force the image.
    I have successfully done this running th following code:
    do shell script "hdiutil attach -passphrase PASSWORDVAR diskimage.dmg
    The PASSWORDVAR changes on every loop to the next consecutive attempt, ie
    aaaaa
    aaaab
    aaaac etc
    When I run the script the command is looping about twice a second which is pretty slow... Is there anyway to speed this up a bit? Any help would be great!
    Thanks,

    You don't show the rest of your script that's building the password to try, so it's possible the problem is there, but the chances are your delay is not in AppleScript, but in hdiutil.
    On its own AppleScript can execute simple loops pretty quickly. However in this case you're calling hdiutil which has to take the parameters, test the password against the disk image, verify the result and then return an error.
    There is some overhead here in AppleScript calling do shell script so you might find better performance if this was a single shell script rather than an AppleScript, but I don't think it'll be a lot different.
    If you have multiple machines you can try to divide and conquer, having each machine start at a different point in the list of possibilities (or one start from the end and work forwards), other than that it's a let-it-run-all-night (week?) kind of thing.

  • Execution of remote shell scripts(on AIX ) from Java Application

    import java.io.BufferedReader;
    import java.io.PrintWriter;
    import java.io.InputStreamReader;
    import java.io.IOException;
    public class Test
         public static void main(String args[])
         throws Exception
              String str = "xxxxxx";
              Runtime rt = Runtime.getRuntime();
              Process p = rt.exec("rsh -l raman 172.16.12.10 ");
              BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
              PrintWriter pw = new PrintWriter(p.getOutputStream());
              pw.println(str);
              pw.println("ls -l");
              pw.flush();
              pw.close();
              while ((str = br.readLine()) != null) {
                   System.out.println(str);
    Hi All,
    I want to login into the remote AIX server and want to execute the shell
    scripts which are available at AIX server.Above program is not executing
    kindly if u have any answer provide me..
    regards
    Rama

    Try JRexec library:
    http://www.jcraft.com/jrexec/

  • Dbbackup shell script error

    hi frnds
    i need a help,i want to use a shell script to shutdown the database if the database is not shutdown properly using shutdown immediate.If shutdown immediate hangs it should check whther the database is up then call another script contains shutdown abort and startup and shutdown.
    The problem is it is not go to the next line when the shutdown immediate hangs.I am giving my script how can i fix this
    with regards
    ramya
    ORACLE_SID=CDRD; export ORACLE_SID
    ALERT=/tmp/dbalert
    dbstop.sh
    sleep 300
    ps -ef | grep ora_smon_$ORACLE_SID >$ALERT
    if test -s $ALERT
    then
    dbabort.sh
    sun7start.sh
    sun7stop.sh
    echo "Database Down"
    else
    echo "Database DOwn"
    fi

    I suppose that when you say "shutdown immediate hangs" you mean that it hangs indefinitely. Shutdown immediate could take a long time to complete for some reason (e.g. SMON has to clean up extents which are no longer needed and mark them as freed).
    I don't know a way to exit from an (indefinitely) hanging process, unless you kill it from another session.
    Maybe shutdown abort is not the most advisable way to go normally, but sometimes you can't avoid it, and personally I've never had problem with it (maybe I'm lucky :-)).

  • Trying to create a shell script to cut/paste files in finder. Help needed.

    I'm trying to create an automator shell script to cut/paste. It'll function exactly like copy/paste. i.e. I'll just copy file/files with command+c like always, but then I'll create an automator which uses the "mv" terminal app to move the files which works exactly like cut paste.
    I need some help since I don't know the syntax for creating shell scripts.
    What I did so far is to do it in automator with Apple Script which goes like the following:
    on run {input, parameters}
    tell application "Finder"
    set theWindow to window 1
    set thePath to quoted form of (POSIX path of (target of theWindow as string))
    end tell
    tell application "Terminal"
    do script with command "mv \"" & input & "\"" & thePath in window 1
    end tell
    return input
    end run
    This gets the copied file path from clipboard before, as input, and then recognizes the active finder window as thePath so then executes the mv command for the input file to the thePath window.
    It doesn't work as expected since it connects both file/window paths into a single path instead of leaving a space between them so the mv command can't recognize two separate paths.
    What's the correct syntax for that line
    do script with command "mv \"" & input & "\"" & thePath in window 1
    to leave a space between input and thePath under the mv command?
    Also this requires the terminal app to be open in the background.
    After I get this to work I want to do the exact same thing using shell script within automator, so I won't need Terminal to be open all the time.
    And the next step will be to cut/paste multiple files/folders but that should be easy to do once I get the hang of it.

    Try using:
    on run {input, parameters}
    tell application "Finder"
    set theWindow to window 1
    set thePath to quoted form of (POSIX path of (target of theWindow as string))
    end tell
    do shell script "mv \"" & input & "\" " & thePath
    return input
    end run
    (45977)

Maybe you are looking for