14 Replies Latest reply on Jun 15, 2012 11:26 AM by Saubhik

    CHMOD FROM A PLSQL?

    mcadena28
      Hello, how I can run a chmod from a plsql block? if they can help me please ..

      Miguel C.
        • 1. Re: CHMOD FROM A PLSQL?
          Hoek
          Have a look here: http://www.oracle-base.com/articles/8i/shell-commands-from-plsql.php
          • 2. Re: CHMOD FROM A PLSQL?
            mcadena28
            I have a problem with the excecution of Java Stored Procedure....

            I am revising this problem:

            CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
            *
            ERROR at line 1:
            ORA-29536: badly formed source: oracle.aurora.sqljdecl.TokenMgrError: Lexical
            error at line 9, column 31. Encountered: "w" (119), after : "\"C:\\"

            -------------------------------------------------------------------------------------------------------------
            CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED 'Host' AS
            *
            ERROR at line 1:
            ORA-29501: invalid or missing Java source, class, or resource name

            -------------------------------------------------------------------------------------------------------------

            CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED Host AS
            *
            ERROR at line 1:
            ORA-29536: badly formed source: Encountered "the" at line 8, column 16.
            Was expecting one of:
            ";" ...
            "." ...
            "[" ...
            "(" ...
            • 3. Re: CHMOD FROM A PLSQL?
              sb92075
              29536, 00000, "badly formed source: %s"
              // *Cause: An attempt was made to create a Java source object with text
              //          that could not be parsed adequately to determine the class(es)
              //          defined by it.
              // *Action: Correct errors in source.
              • 4. Re: CHMOD FROM A PLSQL?
                MichaelS
                how I can run a chmod from a plsql block?
                Another way is via dbms_scheduler, e.g.:
                begin
                   dbms_scheduler.create_job (job_name    => 'myjob',
                                              job_type    => 'executable',
                                              job_action  => '/bin/sh',
                                              number_of_arguments => 2,
                                              auto_drop   => true);
                   dbms_scheduler.set_job_argument_value ('myjob', 1, '-c');
                   dbms_scheduler.set_job_argument_value ('myjob', 2, 'chmod a+r your_files');
                   dbms_scheduler.run_job ('myjob');
                end;
                / 
                • 5. Re: CHMOD FROM A PLSQL?
                  Hoek
                  Can you provide some more details?

                  - OS-version(s)
                  - Database-version ( select * from v$version; )
                  - Are you using SQL Developer or SQL*Plus or PL/SQL Developer or TOAD or...?
                  • 6. Re: CHMOD FROM A PLSQL?
                    mcadena28
                    I have...

                    Solaris 10
                    Oracle 10.2.0.4

                    I require call the chmod at any time...
                    • 7. Re: CHMOD FROM A PLSQL?
                      mcadena28
                      I delete the windows and compiled the Java source
                      • 8. Re: CHMOD FROM A PLSQL?
                        mcadena28
                        there is another way to do it? .. I could with previous methods
                        thanks for their contributions
                        • 9. Re: CHMOD FROM A PLSQL?
                          JustinCave
                          MCADENA87 wrote:
                          there is another way to do it?
                          Another way to do it than what? The Java solution? The DBMS_SCHEDULER solution?
                          I could with previous methods
                          I'm not sure what you're saying here. What "previous methods" are you referring to?

                          Justin
                          • 10. Re: CHMOD FROM A PLSQL?
                            mcadena28
                            1... for run a chmod from a plsql block

                            2... I´m referring to Java Source and Scheduler....
                            • 11. Re: CHMOD FROM A PLSQL?
                              JustinCave
                              Java and DBMS_SCHEDULER are, by far, the most common approaches to calling out to the operating system.

                              What problems do you have with those solutions that leads you to look for a different approach? While we could, undoubtedly, figure out a different approach, it's likely that it would be much more involved than either of the approaches that have been suggested. If we don't know what problem you're trying to overcome, it's rather hard for us to know whether or not any other option would overcome those issues.

                              Justin
                              • 12. Re: CHMOD FROM A PLSQL?
                                Saubhik
                                there is another way to do it? .. I could with previous methods
                                Yes, Why not!. for fun let's try extproc.

                                My system:
                                racle@ubuntu-desktop:/lib$ uname -a
                                Linux ubuntu-desktop 2.6.32-41-generic #89-Ubuntu SMP Fri Apr 27 22:22:09 UTC 2012 i686 GNU/Linux
                                oracle@ubuntu-desktop:/lib$ pwd
                                /lib
                                oracle@ubuntu-desktop:/lib$ ls -l libc.so*
                                lrwxrwxrwx 1 root root 14 2012-04-20 17:22 libc.so.6 -> libc-2.11.1.so
                                oracle@ubuntu-desktop:/lib$ readelf -s libc.so.6|grep chmod
                                   123: 000be750    62 FUNC    WEAK   DEFAULT   12 fchmod@@GLIBC_2.0
                                   616: 000be710    62 FUNC    WEAK   DEFAULT   12 chmod@@GLIBC_2.0
                                   998: 000be790   394 FUNC    GLOBAL DEFAULT   12 fchmodat@@GLIBC_2.4
                                  2056: 000c1920    41 FUNC    GLOBAL DEFAULT   12 lchmod@@GLIBC_2.3.2
                                oracle@ubuntu-desktop:/lib$ 
                                SQL> /* My database version */
                                SQL> SELECT * FROM v$version;
                                
                                BANNER
                                ----------------------------------------------------------------
                                Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
                                PL/SQL Release 10.2.0.1.0 - Production
                                CORE     10.2.0.1.0     Production
                                TNS for Linux: Version 10.2.0.1.0 - Production
                                NLSRTL Version 10.2.0.1.0 - Production
                                
                                SQL> CREATE OR REPLACE LIBRARY libc AS '/lib/libc.so.6';
                                  2  /
                                
                                Library created.
                                Now, the actual code!
                                SQL> ed
                                Wrote file afiedt.buf
                                
                                  1  CREATE OR REPLACE
                                  2  procedure ExecuteCHMOD( filename VARCHAR2, permission binary_integer ) is
                                  3               external
                                  4              library libc
                                  5              name "chmod"
                                  6              language C
                                  7              calling standard C
                                  8             PARAMETERS(
                                  9                   filename string,
                                 10          permission long
                                 11*       );
                                SQL> /
                                
                                Procedure created.
                                So, I have executed the code and saw the result!
                                SQL> EXECUTE ExecuteCHMOD('/home/oracle/gplan.sql','511');
                                
                                PL/SQL procedure successfully completed.
                                oracle@ubuntu-desktop:~$ pwd
                                /home/oracle
                                oracle@ubuntu-desktop:~$ ls -l *.sql
                                -rwxrwxrwx 1 oracle oinstall 2316 2011-06-28 18:12 gplan.sql
                                SQL> SELECT strtol('644',0,8) FROM dual;
                                
                                STRTOL('644',0,8)
                                -----------------
                                           420
                                
                                SQL> EXECUTE ExecuteCHMOD('/home/oracle/gplan.sql','420');
                                
                                PL/SQL procedure successfully completed.
                                
                                SQL> 
                                oracle@ubuntu-desktop:~$ ls -l *.sql
                                -rw-r--r-- 1 oracle oinstall 2316 2011-06-28 18:12 gplan.sql
                                oracle@ubuntu-desktop:~$ 
                                
                                SQL> SELECT strtol('755',0,8) FROM dual;
                                
                                STRTOL('755',0,8)
                                -----------------
                                           493
                                
                                SQL> EXECUTE ExecuteCHMOD('/home/oracle/gplan.sql','493');
                                
                                PL/SQL procedure successfully completed.
                                
                                SQL> 
                                
                                oracle@ubuntu-desktop:~$ ls -l *.sql
                                -rwxr-xr-x 1 oracle oinstall 2316 2011-06-28 18:12 gplan.sql
                                oracle@ubuntu-desktop:~$ 
                                and finally, I am using strtol to convert string to long by this code!
                                CREATE OR REPLACE
                                function StrTol( strval VARCHAR2,dummy binary_integer , base binary_integer  ) RETURN BINARY_INTEGER is
                                             external
                                            LIBRARY libc
                                            name "strtol"
                                            language C
                                            calling standard C
                                           PARAMETERS(
                                                 strval string,
                                        dummy int,
                                        base int,
                                        return long
                                              );
                                Easy and funny! Isn't it ?
                                • 13. Re: CHMOD FROM A PLSQL?
                                  Hoek
                                  You're probably the first person in the world who thinks LONG's are funny, Saubhik ;)
                                  • 14. Re: CHMOD FROM A PLSQL?
                                    Saubhik
                                    Hope OP concurs with me about this alternative approach ;)