Executing if condition in a sql prompt with in a shell script

Hi all,
i need to write a shell script where i need to execute a sql statement. if the count from the above sql is greater than certain value i need to execute a another sql statement.After some time i need to check the count again using above sql and if the count is less than certain value i need to execute a different sql statement. One more time i need to check the count and then i need to get an email.
Could anyone help me in completing this script
Thanks,

Could anyone help me in completing this scriptNot really because "shell script" is OS & Shell dependent & you decided to NOT share these details with us.
Just write a PL/SQL procedure & then you have an OS independent solution!

Similar Messages

  • Error in calling SQL plus program with parameter from Shell script

    This is my Shell script. I am trying to call in the SQL plus program with the parameter and the shell script is registered as a concurrent program.
    PARAMETERS=`echo $1 |tr -d '\"'`
    DB_USER_ID=`echo $PARAMETERS|cut -d" " -f3|cut -d"=" -f2`
    CONN_STRING=$DB_USER_ID
    REQ_DATE=`echo $PARAMETERS|cut -d" " -f9|cut -d"=" -f2`
    timestamp=`date +%m-%d-%y-%H:%M:%S-%Z`
    timestam=`date +%y-%m-%d`
    sqlplus -s $CONN_STRING @ar_statement.sql $REQ_DATE
    chmod 755 statement.sh
    . statement.sh
    My Sql plus program is like this.
    set pagesize 0
    set heading off
    set feedback off
    spool $GEC_TOP/log/ge_ar_statement.sh
    select output_file_name
    from fnd_concurrent_requests
    where trunc(actual_completion_date) = '&2';
    spool off;
    exit;
    When i run the concurrent program, i am getting the following error:
    ar_statement: line 14: REQ_DATE: command not found
    Enter value for 2:
    User requested Interrupt or EOF detected.
    ar_statement.sh: line 1: Enter: command not found
    ar_statement.sh: line 2: User: command not found
    ar_statement
    Program exited with status 127
    I am not strong at Unix Porgamming and i would request someone who can
    help me out as soon as possible.
    I need this solution quickly and thank everyone in advance.
    Thanks.

    Can you put your coding between code statements, like shown in the FAQ. It will be easier to read.
    Looking at your script, my first guess is that crontab will not find your sqlplus since your script does not have $HOME/bin in the $PATH. From what I understand, running .profile in your script will not work either because variables are exported to sub-shells, not to the shell above. You can call your script with a dot like . ./script which means that the script will run like it was typed at the command prompt. But it will be less confusing to define appropriate variables in the script. eg.
    ORACLE_SID=my_instance_name
    ORACLE_HOME=/my_path_to_oracle_home_directory
    LD_LIBRARY_PATH=$ORACLE_HOME/lib
    PATH=$ORACLE_HOME/bin:$PATH
    I remember some slightly different way of coding to handle the sqlplus return codes.
    For instance:
    sqlplus -s /nolog > /dev/null <<-EOF
    connect system/manager
    @ssm.sql
    whenever oserror exit failure
    whenever sqlerror exit failure
    EOF
    sql_err=$?
    if [ $sql_err -ne 0 ]; then
       echo "FAILURE"
    else
       echo "SUCCESS"
    fiThe - in -EOF supresses tab's
    Using connect will prevent ps from showing your login credentials
    In some versions of bash the ending EOF needs to be at the beginning of the line to work.
    Edited by: waldorfm on Jul 14, 2010 7:05 PM
    complaining about putting code between code delimiters and forgot myself ;-)
    Edited by: waldorfm on Jul 14, 2010 7:08 PM
    Btw, if you "source" a script running it like . .script, than an exit in that script will log you out.

  • 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.

  • Problem with the run_job,shell script with sqlldr

    Hi Gurus,
    I Created a job which calls the shell script and i understood from the other posting this job is going to execute with nobody,
    I had done the below testing
    Test 1) Shell script calls the SQL file, this SQL file executes the procedure.
    Test 2) Shell script calls the sqlldr command.
    When i execute the Test cases with , dbms_scheduler Run_job procedure, Test1 is success but Test2 was failed
    When i execute the Test cases with, logging into box with owner of the shell & both test cases are successful.
    Parent folder & Shell files are given with 777 permissions. & the Oracle db is version 10.2.0.1.0.
    Error:
    STANDARD_ERROR="SQL*Loader-522: lfiopn failed for file (*.log)"
    Please provide me your inputs its bit urgent Thanks a lot for your help.
    Edited by: 926769 on May 23, 2012 2:27 PM

    First of all let's look at your environment ... a totally unpatched version of software that is so old it is in desupport mode. You should upgrade to a fully supported version but, if you can't, at least to 10.2.0.5.
    That said without seeing any of your code, or a listing showing permissions on the directory and files, there is insufficient information from which to help you.
    Please post ALL information required for us to understand what you are doing an your environment.
    But before I decided that NOBODY was doing anything ... I'd shell out to the server from SQL*Plus using the HOST command and verify that permissions are as you believe them to be. There is every reason to believe SQL*Loader is having an issue with your file as identified.

  • Starting and stopping an SQL query from within a Shell script

    DB version:10gR2
    OS Version:AIX
    We have a C++ application called WpnCreate.cpp, which is causing some locking problems.
    So, we have decided to capture(using SPOOL) the locking info(session info, blocking program,..etc) using an SQL query.
    WpnCreate.cpp program is initiated by a shell script. So we need this SQL query(.sql) to start firing just before WpnCreate.cpp is called and when WpnCreate.cpp has finished executing, we need the SQL query execution to stop.
    But how do i stop the sql query execution? Should i capture the session id and serial# of this session and use kill -9 at the end of the shell script?
    Flow of the Shell script should be like this
    Step1. Start firing the SQL query which captures the locking info and SPOOL them to a file
    Step2. Execute WpnCreate.cpp program
    Step3. Stop the firing of SQL query once WpnCreate.cpp has finished executing ( i don't know how)How will i go about achieving this?

    How can you run your step 2 untill & unless your step 1 gets over. You can run in background but then it will not capture the correct information.
    I think you need to run your step 1 after step 2 , then only you will be able to capture the information.
    You can run your C++ program in background and can wait for some time using sleep command and then run the query to check the locking information.

  • Problem with running Bash shell scripts

    I am unable to run Bash shell scripts on the UNIX Terminal application.
    This is the transcript from the Terminal application.
    Zhi-Yang-Ongs-Computer:/Applications/MetaPost/metapost-1.102 zhiyangong$ ./test1.sh
    dyld: Symbol not found: _BC
    Referenced from: /usr/local/bin/bash
    Expected in: /usr/lib/libSystem.B.dylib
    Trace/BPT trap
    Zhi-Yang-Ongs-Computer:/Applications/MetaPost/metapost-1.102 zhiyangong$
    Is this a problem with the the default installation of the Bash shell? Can I install the Bash shell on my own? If so, how can I do that?
    Also, how can I get the dynamic linker, dyld, to refer to the symbol "_BC"? What does this symbol "_BC" refer to?

    This was in your posted output:
    /usr/local/bin/bash
    You are NOT running the default bash, you are trying to run a private copy.
    The default Mac OS X bash is located at
    /bin/bash
    Try the following:
    /bin/bash ./test1.sh
    Does that work?
    What is the first line of your script? Is it:
    #!/bin/bash
    Or maybe
    #!/usr/bin/env bash
    /usr/bin/env would find the first bash in PATH . I find this most useful for finding perl on different systems, but sh, ksh, bash, zsh, csh, tcsh are all generally found in /bin so I do not bother using /usr/bin/env
    And if you have
    #!/usr/local/bin/bash
    Then the person that wrote test1.sh choose to use something besides the default bash
    Or maybe this script was transferred from some system where you needed to put your own copy of bash in /usr/local/bin because the vendor does not distribute bash
    Then again, you have not showed us what is inside your script, so it is possible something in the script called something else which invoked the /usr/local/bin/bash
    If that is the case, then you might try:
    /bin/bash -x ./test1.sh
    which should show you the commands executed before it died.

  • Starting Java Program with a bash Shell script

    Hi !
    I know this is a Linux query but I am putting it on this site to get different answers.
    I want to start my Java program with a shell script. Can anybody give me a proper script to start my Java program?
    I am using RH Linux 7.3 and JDK 1.4.
    Can I start the Java program without starting the terminal? Just like the Sun One Studio4 'runide.sh' script.
    Please help.
    Bye Niteen

    assuming you have your PATH and CLASSPATH variables set correctly, your script should look like this:
    #!/bin/bash
    cd <project_dir>
    java <class> &
    example:
    #!/bin/bash
    cd ~/projects
    java project1.main_package.MainClass &
    of course you could add some more elaborated stuff like compiling files before running the program, etc.
    if you dont like terminals, try running "nautilus" (it's like Windows Explorer). i never use nautilus (especially for running scripts), so i cant guarantee it will work, although i dont see why it shouldnt...

  • Help with logic in shell script

    I am on solaris and i have this piece of code.Im using Oracle 10gr2
    Code:
    echo "SQLPLUS CONNECTION"
    sqlplus -s $ARBOR_USR/$ARBOR_DB_PASSWD@$ORACLE_SID<<EOF>$CUR_DIR/sql_output.txt
    set feedback off
    set heading off
    select distinct account_no from adj  WHERE ADJ_TRANS_CODE=-2401 and request_status=1 and bill_ref_no=0
    order by account_no;
    EOF
    if [ $? -eq 0 ]
    then
    echo " SQLPLUS Connection Successful "
    else
    echo " SQLPLUS Connection Failed "
    fi
    ##echo " The account numbers passed to   BIP are  "
    if [  ! -s  "$CUR_DIR/sql_output.txt" ]
    then
    echo "No account number for bad debt"
    else
    for i in `cat $CUR_DIR/sql_output.txt`
    do
    sqlplus -s $ARBOR_USR/$ARBOR_DB_PASSWD@$ORACLE_SID<<EOF1>$CUR_DIR/sql_interim.txt
    insert INTO  t_bill(ACCOUNT_NO,INTERIM_BILL_DATE,INCLUDE_ADJ,PAYMENT_DUE_DATE,TRACKING_ID,TRACKING_ID_SERV )
    select $i,trunc(sysdate),1,trunc(sysdate),0,0 from dual;
    EOF1
    echo "bip $i is running"
    sh  $SCRIPT_DIR/bip.sh 01 0 $i >  $CUR_DIR/bip_log_1.txt
    sleep 200
    done
    fi
    I want to insert the account number into t_bill.TRACKING_ID,TRACKING_ID_SERV columns are composite primary key in the table t_bill.
    The logic behind this is that
    Only 1 row is to be inserted into t_bill table then the bip.sh script runs for a particular account number .When the bip.sh runs the entry for that particular account number
    is deleted from t_bill automatically.
    How to implement this logic? Please correct my above code.

    Through this sql statement i will get few account numbers daily
    select distinct account_no from adj  WHERE ADJ_TRANS_CODE=-2401 and request_status=1 and bill_ref_no=0 
    order by account_no; 
    For eg : i get 3 account numbers(i.e) .
    My main motive :-NowI need to insert 1 account number in  t_bill .
    TRACKING_ID,TRACKING_ID_SERV columns are composite primary key in the table t_bill.I have hard coded it 0,0
    bip.sh is parametrized script taking one account as parameter.
    When i execute the bip.sh the entry of that account num from t_bill is deleted automatically
    Steps i need to implemet
    1.get the account numbers
    2.insert 1 account into t_bill
    3.run the bip.sh for that account number
    i need to do the same process for all account numbers

  • Executing a unix kill from APEX or running a bash shell script from Apex

    I'm writing a browser based app that I would like to write with APEX and that will identify and kill a very specific process name and Unix user name combo.
    I can identify the unix PID in V$SESSION if I want so, I know how to to the first part (identify the process/PID).
    How can an APEX app execute the Linux kill command? I'm not seeing anyway to host out of APEX. I was looking for something like that where you create processes...
    Please provide only suggestions on how to do this from APEX. I know there are lots of other ways (CGI from Apache etc.).

    I have this working, though it's kinda clunky.
    Apex calls Oracle Stored Procedure which calls Java stored procedure which defines a class that runs exec to execute an OS command, and waits for the return value.
    The DBA had to grant special permission for my oracle schema to execute the script name that is passed into the Java.
    Others may have a better way of doing this.

  • [SOLVED]Would be grateful for help with im notification shell script

    Hi all,
    Playing with finch (a console im client), and haven't found any notification plugins for it that work the way I want.
    What I have been doing is using tail to watch the logs. As the logs are in html, I use sed to strip the html tags:
    tail -n 1 -q -f ~/.purple/logs/bonjour/phinch/*/* | sed -e 's#<[^>]*>##g'
    I would like to use notify-send or dzen2 to create popup windows when the log file changes, but I'm not sure how (I am not an experienced programmer).
    This, for example, does not work:
    tail -n 1 -q -f ~/.purple/logs/bonjour/phinch/*/* | sed -e 's#<[^>]*>##g' | while read line ; do notify-send "${line}" ; done
    Removing sed from the stream above allows notify-send to pop up notifications. How can I have the same happen with sed in there?
    Last edited by hellomynameisphil (2011-10-22 17:49:34)

    hellomynameisphil wrote:
    tail -n 1 -q -f ~/.purple/logs/bonjour/phinch/*/* | sed -e 's#<[^>]*>##g' | while read line ; do notify-send "${line}" ; done
    Removing sed from the stream above allows notify-send to pop up notifications. How can I have the same happen with sed in there?
    The problem here is that sed is buffering its output to improve efficiency in pipes. Try with:
    tail -n 1 -q -f ~/.purple/logs/bonjour/phinch/*/* | sed -e 's#<[^>]*>##g' -u | while read line ; do notify-send "${line}" ; done
    And should work as well
    Regards

  • Runtime.exec with a unix shell script

    I've done a lot of google'ing and haven't found a definitive answer to my question, including the JavaWorld article that is pointed to quite often. Scenario1 - The program calling Runtime.exec is running in /dir1 and I have a script called test.sh in /dir2 (neither directory are in the path). If I call Runtime.exec("test.sh", null, "/dir2"), I get java.io.IOException: test.sh: not found. However, if I do "touch test.sh" AND "chmod +x test.sh" in /dir1 and call the same exec, it works AND runs the script in /dir2 not /dir1?!?! Also, if I copy /dir2/test.sh /dir1/test.sh and I call exec("test.sh"), it works fine. Scenario2 - If I get rid of /dir1/test.sh and call exec("/dir2/test.sh", null, "/dir2") OR exec("/bin/sh test.sh", null, "/dir2") - both of those work. I just don't get Scenario1. Why does having the dummy executable test.sh in /dir1 allow it to run in /dir2 OR if the script is in the local directory of the process calling exec, why does it work without adding the path? It doesn't seem consistent. Seems like the working directory I specify isn't set before trying to run it or something. On the flip side, if I have a java class in /dir2 called test.class, I can call exec("java test", null, "/dir2") and it just runs without jumping through any hoops - although I think the explanation for that is that "java" is in the path. Let me know what you think.
    Gary

    I think the problem is that the three argument version of exec specifies the command to run (should be full path to it if it is not in the current dir), the environment, then the working directory. The working directory will not help java to find the command to run in the first place. The following does work as you say:
    Runtime.exec("/bin/sh test.sh",null,"/dir2");This is because the full path to the command (/bin/sh) is specified, that runs in directory /dir2 then tries to find test.sh which it finds there.
    Basically to run anything, you should specify the full path in the command, the working directory will not help java find it.
    Dave

  • How to tell if item is a folder or volume with applescript or shell script?

    I am working on a service in Automator that will eject the selected drive when it is finished. Unfortunately automator can only tell the difference between files and folders for the service menu.
    Im wondering if if i can use an applescript or shell script that would check if the selected folder is a volume or folder and quit the action if its a folder. I figure the best way to do this is have it determine if the items path is in /Volumes/, but i am completely new to the process and have no idea how to do this.
    My automator workflow looks like:
    Ask for Confirmation
    Get Selected Finder Items
    Shell Script
    I have the path of the folder selected being passed into the shell script, but after its in there i dont know how to determine if its a volume or not.
    Thanks!

    K T,
    I completely missed that section of the forums, sorry
    Neil,
    I had that kind of script set up but it was like this:
    on run {input, parameters}
    tell application "Finder"
    kind of item parameters
    end tell
    end run
    And i just figured out that i had to change the first line to "on run {parameters}" and now it works great.
    Thanks for the help, it got me going in the right direction

  • Dealing with spaces in shell scripts

    I have read everything I can about quotes (single and double), backslash and more and I'm stuck.
    I need to compare files to do some make like things. Many of the files have spaces in the name. Here's the script:
    #!/bin/sh
    ROOT=$HOME
    PROJECT="/Documents/MMM/Victoria/Documentation"
    FILE="/Audio Control 1.0 a1.pages"
    FULLPATH="${ROOT}${PROJECT}${FILE}"
    echo ls -l \"$FULLPATH\"
    ls -l \"$FULLPATH\"
    and here's the output:
    ls -l "/Users/wesM/Documents/MMM/Victoria/Documentation/Audio Control 1.0 a1.pages"
    ls: "/Users/wesM/Documents/MMM/Victoria/Documentation/Audio: No such file or directory
    ls: 1.0: No such file or directory
    ls: Control: No such file or directory
    ls: a1.pages": No such file or directory
    what's echoed looks exactly right, and if I copy and paste to a shell, it works fine, but when run from within the script, its acting like the double quotes are not there?

    If what I'm seeing in the post
    ls -l "$FULLPATH"
    is correct, then you have told the shell "These are not the quotes you are looking for". So the shell did NOT treat the double quotes as having an special meaning, removed the backslashes, parsed the string into 4 arguments, and passed the 4 arguments including the leading and trailing quotes to the ls command:
    arg[1]: "/Users/wesM/Documents/MMM/Victoria/Documentation/Audio
    arg[2]: Control
    arg[3]: 1.0
    arg[4]: a1.pages"
    Notice that the leading double quote is part of arg[1], and the trailing double quota is part of arg[4].
    You most likely wanted to say something like:
    echo ls -l ""$FULLPATH""
    ls -l "$FULLPATH"
    Notice that I added an extra layer of double quotes to the echo command. The first layer of double quotes tells the shell that this is a single argument. The backslash double quotes tells the shell that these quotes inside of a double quoted string are NOT terminating the string, but rather are to be treated as part of the string.
    And no backslashes on the ls command tells the shell that whatever $FULLPATH expands to is to be treated as a single argument.
    Always remember it is the shell that parses the command line into tokens so it is also the shell that handles the quoting. The command is just handed an array of strings already broken into individual arguments. The command does not see the quotes. The command does not see the variables.

  • How can I execute a Procedure with OUT variable is %ROWTYPE on SQL Prompt

    Hi,
    I have a procedure with OUT variable is %ROWTYPE
    How can I execute the following procedure on SQL prompt.
    (without creating anonymous block)
    CREATE OR REPLACE PROCEDURE zz_sp_EMP(VEMPNO IN EMP.EMPNO%TYPE,
    V_REC IN OUT EMP%ROWTYPE)
    AS
    BEGIN
    SELECT * INTO V_REC FROM EMP WHERE EMPNO = VEMPNO;
    END;
    Thanks & Regards,
    Naresh

    as previous posters said: it's not possible to do this without declaring a variable in the anonymous block.
    With anonymous block it would look like this (had to change it a bit, since i'm using hr-schema on oracle XE):
    declare
    l_rec EMPLOYEES%ROWTYPE;
    begin
    zz_sp_EMP(VEMPNO => 100, V_REC => l_rec);
    DBMS_OUTPUT.PUT_LINE ( 'first_name = ' || l_rec.first_name );
    DBMS_OUTPUT.PUT_LINE ( 'last_name = ' || l_rec.last_name );
    end;
    first_name = Steven
    last_name = King

  • How to write java hello world to run in oracle sql prompt

    Hi,
    I'm newbie of this chapter. I know JDBC. I wanted to introduce the JDBC process & start executing the same in orcle sql prompt.
    Do enlighten with an example.
    Thnx in Advance

    create or replace and compile java source named helloworld as
    public class HELLOWORLD{public static String HELLOWORLD() {return "Hello World";}}
    create or replace function printhelloworld return varchar2 as
    language java name 'HELLOWORLD.HELLOWORLD() return String';
    SQL> select printhelloworld from dual;
    Hello WorldRegards
    Laurent

Maybe you are looking for

  • Code working on Windows but not in Unix

    Hello, I try to test a https connection. My method is to accept all kind of certificat. Under Windows this code works well and return true when Itest the https connection but under Unix it returns false. Why if I accept all certificat , that does not

  • My husband and i both have an iphone 5. we are having trouble using two itunes accounts on one computer

    My husband and I both have an iphone5.  I had mine first and setup my itunes account.  When we purchased his phone we sent up another itunes account but on the same computer.  Now we are running into problems, especially when he wants to set up playl

  • Historical warehouse material movements

    Hello Our client needs a report listing all the warehouse material movements that occured for a given date range. Is there a SAP standard report to meet this requirement? If not, what are the basic requirements (tables, badi etc) that should be looke

  • BOM Data

    Hi BW Gurus,        I have requirement where user wants report on BOM Usage. Here I m clear on data coming from R/3. BOM stucture which has parent material and its component is from transaction CS03 that is table MAST and STPO. The material consumpti

  • XSTL-JAVA error Illegal number of arguments or types of arguments in a call

    Hi All, I get this error when invoking my Java function from XSLT.I am passing Strings with global param defined like this . <xsl:param name="inputparam"/> <xsl:param name="gid" select="//GENERAL_ID"/> <xsl:param name="vtype" select="//VESSEL"/> <xsl