5 Replies Latest reply: Mar 10, 2014 4:32 AM by 994543 RSS

    Passing parameter / variable to linux script

    994543

      Hello,

       

      I am trying to make Oracle work with schell script in Linux and i require two parameters to run it ( linux script that is).

       

      Is there a way to pass parameters to linux using a job or program ?

       

      I need to run my script as /scripts/sh script.sh parameter1 parameter2

       

      Thank you!

        • 1. Re: Passing parameter / variable to linux script
          Partha Sarathy S

          You are using this script to execute a job in oracle? If so, you can check this.

           

          creating a job with arguments

           

          Message was edited by: Partha Sarathy S

          • 2. Re: Passing parameter / variable to linux script
            KarK

            vi script.sh

             

            parameter1=$1
            parameter1=$2

            echo "variable 1 is : $parameter1"
            echo "variable 2 is : $parameter1"

             

            ---- Use those variables in your remaining code

             

            Execute the code by passing the value for the parameters:

             

            sh script.sh parameter1 parameter2

             

            • 4. Re: Passing parameter / variable to linux script
              Bawer

              [code]

              import java.io.*;

              import java.util.ArrayList;

               

                  public class Util extends Object {

               

                   public static String RunThis(String args){

                       Runtime rt = Runtime.getRuntime();

                       String result = "";

                       ArrayList<String> res = new ArrayList<String>();

               

                       try {

                       String[] cmd = {

                                   "/bin/sh",

                                   "-c",

                                   args

                                   };

                          Process p = rt.exec(cmd);    

                          BufferedReader br_in = null;

                          br_in = new BufferedReader(new InputStreamReader(p.getInputStream()));

                          String buff = null;

               

                          while ((buff = br_in.readLine())!= null) res.add(buff);

               

                          for (int i = 0; i< res.size() ; i++) {

                              if (i > 0) result += "\n";

                              result += res.get(i);

                          }

               

                          int rc = p.waitFor();

                       }

                       catch (Exception e) {

                          e.printStackTrace();

                          result += e.getMessage();

                       }

                       finally {

                          return result ;

                       }

                   }

              }

              [/code]

               

              [code]

              create or replace function RUN_OS_COMMAND( p_cmd  in varchar2) return varchar2

              as

              language java

              name 'Util.RunThis(java.lang.String) return java.lang.String';

              [/code]

               

              and give execute right to user

              [code]

              call dbms_java.grant_permission('USERNAME','SYS:java.io.FilePermission', '/usr/bin/zip', 'execute');commit;

              [/code]

               

              call the procedure with your arguments.

               

              execute dbms_output.put_line( RUN_OS_COMMAND('/usr/bin/zip param1 param2 param3...') );

              • 5. Re: Passing parameter / variable to linux script
                994543

                Spot on mate!

                 

                The only thing that i forgot to uncomment in my script

                parameter1=$1

                parameter1=$2


                stupid mistake ... thank you again!