Commands in shell script

Hai all,
I need to write a script to add in the cron
     a) exec a procedure
if successful ,then
     b) Truncate one schema table in the DB
     c) exec a procedure
Can anyone let me know how to do this ? if anyone have any pointers, for the same , please let me know
DB : 11.
Os: Solaris 5.10
Kai

Kai,
Here are 3 function you can use in shell script for executing a statement, sqlfile and procedure
function execStmt {
  typeset stmt=$4
  echo "
    set feedback off
    set verify off
    set heading off
    set pagesize 0
    whenever sqlerror exit 1
    whenever oserror exit 2
    $stmt;
    commit;
    exit 0
  " |  sqlplus -s  $1/$2@$3
  ret=$?
  if [ $ret -ne 0 ]
   then
      return 1;
   else
      return 0;
   fi
function execSql {
  typeset sqlfile=$1
  if [ ! -f $sqlfile ]
  then
       echo
       echo "File containing extract count doesn't exist...." 
       echo "Exiting ..."
       echo
       exit 1;
  fi
  echo "
    set feedback off
    set verify off
    set heading off
    set pagesize 0
    whenever sqlerror exit 1
    whenever oserror exit 2
    @$sqlfile;
    exit 0
  " |  sqlplus -s  $2/$3@$4
  retcode=$?
  if [ $retcode -ne 0 ]
  then
       return 1;
  else
       return 0;
  fi
function execPkg {
   echo "
   set feedback off
   set verify off
   set heading off
   set pagesize 0
   whenever sqlerror exit 1
   whenever oserror exit 2
   exec mypkg.procedure_name($4,$5); -- $4,$5 are argument list
    exit
  " |  sqlplus -s  $1/$2@$3
  ret=$?
  if [ $ret -ne 0 ]
  then
       return 1;
  else
       return 0;
  fi
}Regards

Similar Messages

  • Update command in Shell script

    Hi friends
    sqlplus -s / <<END
    set feedback on;
    update tran2 set sno=1;
    exit;
    END
    when i am using update command in shell script like above
    it is updating the database well...but i just want to know how many rows it is updating and i dont want to commit
    for that
    sqlplus -s / <<END
    set feedback on;
    update tran2 set sno=1;
    set feedback off;
    rollback;
    exit;
    END
    It's working fine
    is there any other method to do the same

    Well what's exactly your requirement? The current requirement doesn't make a lot of sense.
    How many row is going to be updated depends on where clause, if you have no where clause that essentially updating whole table, the number of row updated is count of your rows.

  • How to call a HP-UX command or shell script from Forms 4.5

    Does anybody know how to call a unix command or shell script to get a files list of HP-UX server from Oracle Forms 4.5 on client side? I tried to use DBMS_PIPE package to get it done but I failed. Please let me have the solution if anybody knows how. Very urgent!

    I tried the host command before and it just let me shell to the DOS environment but not HP-UX environment as Forms was running on Windows platform. So, I could not run a unix command or a shell script. Is DBMS_PIPE the only way to get it done?

  • FTP command in shell script

    Hello All,
    I would like to transfer a file from one system to another system.
    so i haven written shell script with ftp command as follows.
    ftp -i 10.14.12.1<< END
    cd C:\Temp
    put $datafile
    ascii
    quit
    But i am getting error.
    Please let me know the sysntax followed by me is correct or thar remote system is down,
    Many thanks,
    Kumar.

    The ftp(1) command is not well-suited for scripting. Instead us the curl(1) tool:
    curl -T myfile ftp://ftp.some.where/down/in/this/dir/
    for example.
    $ man 1 curl
    for more details.

  • Output format of sqlplus commands under shell script

    hi experts
    Can you help with some problems please?
    1.) I try to run shell script from dbms_scheduler, which runs sqlplus and the output of sqlplus commands is written to file using command spool. To this point everything is running ok.
    My problem is, that output of this file is: (e.g.)
    SQL> PROMPT ****************USERB******************
    ****************USERB******************
    SQL> --SELECT sid
    SQL> -- FROM v
    SQL> -- WHERE audsid = SYS_CONTEXT('userenv','sessionid');
    But I don't want the whole first line in the output file. I only want the output of this command, like on the second line.
    2.) How Can I write two outputs from sqlplus using command spool running at the same time into one file?
    Like in first issue described above. The main sqlplus create a job and this execute the background sqlplus using shell script. But both, the main and the background sqlplus are written to output file at the same time. But only one is written into. But I want the both outputs in the file.
    How Can I do that, if I can?
    Thanks a lot.

    user9357436 wrote:
    hi experts
    Can you help with some problems please?
    1.) I try to run shell script from dbms_scheduler, which runs sqlplus and the output of sqlplus commands is written to file using command spool. To this point everything is running ok. then why are you here?
    My problem is, that output of this file is: (e.g.)
    SQL> PROMPT ****************USERB******************
    ****************USERB******************so remove PROMPT line from the file
    >
    SQL> --SELECT sid
    SQL> -- FROM v
    SQL> -- WHERE audsid = SYS_CONTEXT('userenv','sessionid');
    But I don't want the whole first line in the output file. I only want the output of this command, like on the second line.
    2.) How Can I write two outputs from sqlplus using command spool running at the same time into one file?you can not do so.
    Like in first issue described above. The main sqlplus create a job and this execute the background sqlplus using shell script. But both, the main and the background sqlplus are written to output file at the same time. But only one is written into. But I want the both outputs in the file.
    How Can I do that, if I can?Can't.
    Now what?
    >
    Thanks a lot.Why using DBMS_SCHEDULER to invoke OS script to run sqlplus that runs SQL statements?
    this is like making THREE Left Turns, instead of single Right Turn.
    Just invoke PL/SQL procedure that does what needs to be done.

  • Turn commands into shell script

    Hey. I want to do this repetitive task and I'd like to write a shell script to do it. The commands that I want the machine to repeat look like this:
    cd /srv/web-data/conferences
    pwd
    ls -al >> /srv/web-data/work.txt
    cd /srv/web-data/conferences/gurt99
    pwd
    ls -al >> /srv/web-data/conferences/gurt99
    And the machine I'm working on tells me this about itself:
    System = SunOS
    Node = gusun
    Release = 5.8
    KernelID = Generic_108528-10
    Machine = sun4u
    BusType =
    Serial =
    Users =
    OEM# = 0
    Origin# = 1
    NumCPU = 5
    What do I have to do to turn a text file with a list of commands like the above into a shell script?
    Thanks, Rebecca

    Kai,
    Here are 3 function you can use in shell script for executing a statement, sqlfile and procedure
    function execStmt {
      typeset stmt=$4
      echo "
        set feedback off
        set verify off
        set heading off
        set pagesize 0
        whenever sqlerror exit 1
        whenever oserror exit 2
        $stmt;
        commit;
        exit 0
      " |  sqlplus -s  $1/$2@$3
      ret=$?
      if [ $ret -ne 0 ]
       then
          return 1;
       else
          return 0;
       fi
    function execSql {
      typeset sqlfile=$1
      if [ ! -f $sqlfile ]
      then
           echo
           echo "File containing extract count doesn't exist...." 
           echo "Exiting ..."
           echo
           exit 1;
      fi
      echo "
        set feedback off
        set verify off
        set heading off
        set pagesize 0
        whenever sqlerror exit 1
        whenever oserror exit 2
        @$sqlfile;
        exit 0
      " |  sqlplus -s  $2/$3@$4
      retcode=$?
      if [ $retcode -ne 0 ]
      then
           return 1;
      else
           return 0;
      fi
    function execPkg {
       echo "
       set feedback off
       set verify off
       set heading off
       set pagesize 0
       whenever sqlerror exit 1
       whenever oserror exit 2
       exec mypkg.procedure_name($4,$5); -- $4,$5 are argument list
        exit
      " |  sqlplus -s  $1/$2@$3
      ret=$?
      if [ $ret -ne 0 ]
      then
           return 1;
      else
           return 0;
      fi
    }Regards

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

  • Airport Command Line / Shell Script Tool

    Hi,
    Is there a way to issue a command to cause an Airport Extreme to reboot? I need to restart my airport extreme fairly often.
    Thanks,
    Bruce

    Hi,
    try OMBPlus.
    #Connect to repository:
    OMBCONNECT owbrep/passwd@mydesignhost:1521:mydesignrep USE REPOSITORY 'owbrep'
    #Export
    OMBEXPORT MDL_FILE 'C:\\file.mdl' FROM PROJECT 'MY_PROJECT' WITH DEPENDEE_DEPTH MAX INCLUDE_USER_DEFINITIONS OUTPUT LOG 'C:\\file.log'
    OMBDISCONNECT
    This export one project. If you want to export all projects, don't forget the project "PUBLIC_PROJECT", that contains all public stuff.
    Put this into a script and here you go.
    Checkout the OWB API and Scipting Guide for more options on OMBEXPORT.
    Regards,
    Carsten.

  • Do shell script problem in Applescript

    Hi,
    I am an Applescript novice and have been trying to write a code to go to a particular folder, look for all files in the folder tree with extension .m2v and run an executable file to decode them. My problem is that when I run my code (containing do shell script), it searches through all files and folders on Mac HD and starts decoding .m2v files elsewhere that I don't want.
    Eventually it runs out of space (.m2v file decoding takes a lot of space), because it is dumping all decoded .yuv files onto the HD.
    When I run the command on Terminal, it executes the decoding perfectly and stores the decoded files in the same folder.
    Please help me about what's going on.
    My code is something like:
    tell application "Finder"
    set DestinationFolder to "xxxxxx:xxxx:xxxx"
    set NumFolders to (get count of folders under Destination folder)
    repeat for SomeVar from 1 to NumFolders
    set FolderinQuestion to folder SomeVar of DestinationFolder
    -- Tried tell application "Terminal" here, but did not know --how to export the FolderinQuestion variable from Finder to --Terminal
    do shell script " \" cd \" & (POSIX path of (result as text));
    for file in `find $pwd \"*.mov\"`
    do
    /usr/local/bin/decode file
    done"
    end repeat
    end tell
    I would greatly appreciate some guidance.

    The root of the problem is that you're trying to quote the cd command for some reason:
    <pre class=command>do shell script " \" cd \" & (POSIX path of (result as text));
    ...</pre>
    In addition to that you're including the & (POSIX path of (result as text)) as part of the shell command whereas this should be OUTSIDE of the quotes in order to get evaluated
    If you work that through you'll end up with a shell command that looks like:
    <pre class=command>" cd " & (POSIX path of (result as text))</pre>
    If you try to run that in a terminal you'll get a cd : command not found error and that's why the rest of it appears to fail.
    The solution to that one is simple - just don't bother quoting the cd and put the POSIX path stuff outside of the quotes to get it evaluated at runtime:
    <pre class=command>do shell script "cd " & quoted form of POSIX path of (FolderInQuestion as text)) & ";
    # rest of shell commands here"</pre>
    Now, as for the rest of the script there are a few things I would change.
    First, unless you need to know the index, don't do:
    >repeat for SomeVar from 1 to NumFolders
    set FolderinQuestion to folder SomeVar of DestinationFolder
    the issue is that the number of folders to process may change during the script's execution (other processes may create or remove folders). This will, at best, cause some folders to be skipped and, at worst, cause the script to fail.
    If you're iterating through a list, the best option is to just:
    <pre class=command>repeat with FolderInQuestion in (folders of DestinationFolder)
    ...</pre>
    This automatically sets the iterator (in this case, FolderInQuestion, to the first item in the list and increments it for each iteration through the loop.
    Secondly, in your shell script itself, scrub the entire do/done loop. You're already using find, so have that do the hard work using the -exec switch:
    <pre class=command>find path -name "*.mov" -exec /usr/local/bin/decode {} \;</pre>
    In find's case, {} is substituted with the current file's path.
    Putting this together you'd get:
    <pre class=command>tell application "Finder"
    set DestinationFolder to "xxxxxx:xxxx:xxxx"
    repeat with folderInQuestion in (get folders of folder DestinationFolder)
    do shell script "cd " & quoted form of POSIX path of folderInQuestion & "; find . -name \"*.mov\" -exec /usr/bin/decode {} \\;"
    end repeat
    end tell</pre>
    Note that I've used 'quoted form of POSIX path' - this takes care of any shell-unsafe characters like spaces in the path name. I've also used \\; for the -exec switch - this is so that AppleScript passes the \ to the shell command rather than using it for its own escaping.
    But you're not done yet!
    There's still one fatal flaw in this process - and that is the fact that find by default, is recursive - it will walk through every directory that it finds.
    This means that if you start at the top folder and iterate through, find will find all .mov files and decode them. Your script then cd's to the first subdirectory and repeats the process - decoding all the .mov files in that directory and all its subdirectories even though they've ALREADY been decoded.
    The upshot is that you only need to run one loop starting at the top level. You don't need to iterate through all the subdirectories since find will do that for you.
    In addition to that, there might not be a need to use cd at all since the first argument to find is the directory to start searching in. Unless there's some reason that you need to start decode from the top level directory (e.g. is that where it saves the files?), you can drop the whole repeat loop altogether and just run with:
    <pre class=command>set startFolder to (choose folder)
    do shell script "find " & quoted form of posix path of startFolder & " -name \"*.mov\" -exec /usr/bin/decode {} \\;"</pre>
    That's the entire script - a radical compression of your original.

  • Importing thru a shell script

    I want to import thru a shell script..in oracle 10g rel 2. on RHEL4
    Is there any way thru which i can mimic the file open dialog box in windows in Linux here.
    So that i can call the file open dialog and browse for the particular file to import.
    which will be concatenated in a string in ...imp command in shell script..
    Else how do i input the file name (to import) in a shell script from the user..

    I want to import thru a shell script..in oracle 10g
    rel 2. on RHEL4
    Is there any way thru which i can mimic the file open
    dialog box in windows in Linux here.
    So that i can call the file open dialog and browse
    for the particular file to import.
    which will be concatenated in a string in ...imp
    command in shell script..You would just to use the database control which comes with 10g, and has all this functionality,and can generate a script on the fly.
    >
    Else how do i input the file name (to import) in a
    shell script from the user..In what scripting language? This rather not an Oracle question but an Unix question. You would just need to type
    man read
    on the command prompt, and you should be set.
    Sybrand Bakker
    Senior Oracle DBA

  • Execute a shell script from inside PL procedure

    Oracle 9205 on Red Hat Enterprise Linux 3.
    Is there any way to execute an O.S. shell script from inside a PL/SQL procedure?
    This is, that PL_SQL procedure evaluate a situation and if the condition is true, it calls and execute an O.S. shell script.

    PL/SQL procedures do not support any native calls to the OS; however, you can code calls to external procedures or JAVA procedures to perform tasks on the OS.
    Prior to these two methods any of the following packages dbms_alert, dbms_pipe, or utl_file could be combined with a daemon type program to issue OS commands, run shell scripts, etc....
    There is a writeup on metalink with examples.
    HTH -- Mark D Powell --

  • SAP and Korn shell scripts

    Hi,
    It looks SAP default is c-shell only.  I have an issue, when remote calls (rsh) to OS to run a command, k-shell script does not source the .profile.  Do any one face this issue? how it was resolved.
    Thanks, R

    Hi,
    It is a very, very long time, but as far as I remember that is an issue with the rsh.
    I think the solution is not to use the Ksh on the destination.
    I think there is/was a note indicating so.
    For that reason SAP does recommend to use only the cshell.
    Edited by: Fidel Vales on Nov 14, 2009 11:02 AM
    hi again.
    Check note 202227.
    > In general, you can use the Korn shell (ksh) as a login shell, however, note that the implementation of the Korn shell differs among the different UNIX platforms. This has lead to problems within SAP, in particular this is the case when you start external programs from an SAP system.
    and note 188772
    > The .profile file is not read under ksh.

  • Automator/Applescript not running shell script properly

    I can open Terminal, and this command works:
    lame -h --abr 256 /Users/myhome/Desktop/Some\ Wav\ File.wav /Users/myhome/Desktop/TheMP3.mp3
    But when I try to run the same command in applescript from Automator, it fails.
    set sourceFile to quoted form of POSIX path of "/Users/myhome/Desktop/Some Wav File.wav"
    set mp3File to quoted form of POSIX path of "/Users/myhome/Desktop/TheMP3.mp3"
    set command to "lame -h --abr 256 " & sourceFile & " " & mp3File
    display dialog command
    do shell script command
    The display dialog outputs:
    lame -h --abr 256 '/Users/myhome/Desktop/Some Wav File.wav' '/Users/myhome/Desktop/TheMP3.mp3'
    Which, as little as I know of applescript, is how applescript handles spaces in filesnames. Can anyone please help?

    You need *do shell script* attribute described in the 10.4 Changes section of http://developer.apple.com/mac/library/releasenotes/AppleScript/RN-AppleScript/R N-104/RN-10_4.html#//appleref/doc/uid/TP40000982-CH104-SW1 Additional info can be gained by posting to the AppleScript and Unix forums under OS X Technologies.

  • Hardcode password in a do shell script not working

    I have been trying to solve something i have wanted to do for a long time, that is get a script that changes the ammount of time before the display goes to sleep. I tried GUi scripting but in system preferences the changes made to the slider did not stay. So i have now come onto a do shell script. Found below. I would prefer to just hardcode my password into it however this does not seem to work. Any ideas ?
    set exitflag to false
    try
    repeat until exitflag is true
    set {text returned:Sleeptime, button returned:sleepstate} to (display dialog "Minutes before display sleep" & return & "Between 1 and 180 mintues" & return & "Greater than 180 means never sleep" default answer "1" buttons {"Cancel", "OK"} default button 2)
    set Sleeptime to Sleeptime as number
    if Sleeptime is less than 1 then
    set exitflag to false
    else if Sleeptime is greater than 180 then
    set Sleeptime to 0
    set exitflag to true
    else
    set exitflag to true
    end if
    end repeat
    end try
    set Sleeptime1 to Sleeptime as string
    set Sleeptime1 to quoted form of Sleeptime1
    set psswd to quoted form of "XXXXX"
    do shell script "sudo pmset -a displaysleep " & Sleeptime1 password psswd
    set pete to do shell script "sudo pmset -g"
    set xx to text -2 thru -1 of pete
    if xx - Sleeptime = 0 then
    tell application "SEC Helper"
    show screen message "Worked:" & return & xx & " mintues"
    end tell
    else
    tell application "SEC Helper"
    show screen message "Failed!"
    end tell
    end if

    1) don't use 'sudo' in a 'do shell script'. It isn't necessary and will sometimes break.
    2) do not use 'sudo' in a 'do shell script'
    3) do not use... I'm sure you get the idea.
    It is not necessary to use 'sudo' in a 'do shell script' command. 'do shell script' itself takes care of the authentication element when you use 'with administrator privileges'. Therefore the appropriate way of doing this is:
    <pre class=command>do shell script "pmset -g displaysleep " & sleeptime1 with administrator privileges password psswd</pre>
    If you omit the 'password psswd' element the user will be prompted to authenticate using the standard system authentication dialog.
    The problem you're running into is that the 'password' parameter is only valid when you use 'with adminitrator privileges', and is therefore getting ignored in your current script.

  • Shell Script - Sleep

    Hello All,
    We are printing pdf file outputs from shell script. Here we faced a problem that the shell script tried to access the output file(pdf file) while the concurrent program is running. For that we added the concurrent program names into shell script programs incompatibility list. This is working fine.
    But there are more than 20 reports using the same shell script. If all the programs are running shell script waits until all the 20 programs completed.
    I am thinking of another solution that, I have to issue a sleep command in shell script until the program completes, or until the output file is generated and the shell script can generate post script file from the output file.
    I dont know what kind of lock the concurrent program is using, because shell script says no such file or directory while generating post script file.
    Kindly help.

    You would probably find more concurrent manager experts in the Apps forums. You could try using the output of ps -ef to see if the program your script should wait for is still running. Or you can use the lsof command to see if the file you are supposed to process is still open in another process. For example, lsof -f -- /output/my.pdf shows all processes that have the file /output/my.pdf open.
    Edited by: herb on Jan 11, 2010 11:47 PM

Maybe you are looking for