UTL_FILE invalid file operation ORA-29283: invalid file operation



lab2>exec ping_sh_file_gen('VM','10.35.9.65');

ORA-29283: invalid file operation

ORA-06512: at "SYS.UTL_FILE", line 449

ORA-29283: invalid file operation

 
PL/SQL procedure successfully completed.

Solution



lab2>select * from dba_directories;

 

lab2>set lines 10000

lab2>/

 

OWNER                          DIRECTORY_NAME                 DIRECTORY_PATH

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

SYS                            PING_DIR                       /apps

 


create or replace procedure PING_SH_FILE_GEN(pdblink in varchar2,ping_ip in varchar2)

IS

     FH  UTL_FILE.FILE_TYPE;

     ln  VARCHAR2(2000);

 

BEGIN

 

 IF UTL_FILE.IS_OPEN (FH)

      THEN UTL_FILE.FCLOSE (FH);

   END IF;

 

FH :=UTL_FILE.FOPEN ('PING_DIR','ping.sh','W'); -- ping_dir changed to PING_DIR

 

                                                                    UTL_FILE.PUT_LINE(FH,'#!/bin/sh');

                                                                    UTL_FILE.NEW_LINE (fh);

   

                                                                    UTL_FILE.PUT_LINE(FH,'/bin/date > /apps/pingraj.txt');

 

                                                                    UTL_FILE.NEW_LINE (fh);

 

UTL_FILE.PUT_LINE(FH,'echo Checking network of ... ... '||pdblink||' >> /apps/pingraj.txt');

 

  UTL_FILE.NEW_LINE (fh);

 

  ln:= '/bin/ping -c 6 '||ping_ip||' >> /apps/pingraj.txt';

 

  UTL_FILE.PUT_LINE(FH,ln);

  UTL_FILE.FCLOSE(FH);

 

EXCEPTION

    WHEN NO_DATA_FOUND THEN

     UTL_FILE.FCLOSE(FH);

     COMMIT;

    WHEN utl_file.invalid_path THEN

     raise_application_error(-20000,'ERROR: Invalid path. Create directory or set UTL_FILE_DIR.');

     UTL_FILE.FCLOSE(FH);

    WHEN OTHERS THEN

     DBMS_OUTPUT.PUT_LINE(SQLERRM(SQLCODE));

     UTL_FILE.FCLOSE(FH);

END;

/

 

-- ping_dir changed to PING_DIR     directory name is CASE SENSITIVE
 

Post a Comment

And that's all there is to it!

If anyone has any other questions or requests for future How To posts, you can either ask them in the comments or email me. Please don't feel shy at all!

I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.

Previous Post Next Post