Shell Scripting - CHMOD issue

Hi Friends ,

good morning . I am very new to Unix scripting and require a bit of advice to help resolve the below issue . Hope some one can provide some suggestion

I have the below script which calls a Oracle stored procedure which inturn extracts data from a table and writes in a ascii file (nameextract.txt) .

Although the file is created but i am getting the below error
----------------------------------------------
script log -

connected to oracle db 
SQL>
PL/SQL procedure completed successfully
SQL>disconnected from database
/x01/data/dataextract/code/extract.sh[16]:chmod not found

----------------------------------------------
code
----------------------------------------------

#!/bin/ksh
#setup tns to point to oracle wallet
export TNS_ADMIN=/x01/user/oracle/product/11.2.0.4/wallet
export ORACLE_HOME=/x01/user/userhome/oracle/product/11.2.0.4
ORACLE_SID=NAME_OWNER
PATH=$ORACLE_HOME/bin PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
ORACLE_HOME/network/lib
export LIBPATH=($LD_LIBRARY_PATH):/user/lib:/lib
export ORACLE_HOME ORACLE_SID PATH
sqlplus /@NAME_OWNER<<EOF
exec runstoredproc;
exit
EOF
chmod 674 /x01/data/dataextract/nameextract.txt

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

Thanks in advance

For a reason I do not see immediately, it means the environment does not know where the chmod executable file lives.

So, a quick fix is: change chmod to /usr/bin/chmod
But bear in mind something went wrong, probably in the setup script for the user running the job in the first place. This can bite you badly in some other script.

BTW: chmod 674? Probably should be 664. It is a text file, right? Not an executable.

Hi Jim - Thanks for your response . I don't have access to the box over the weekend , will try out your suggestion on Monday. Is it advisable to re export the path before chmod ?

I mean can i try the following -

and you are right i need 664 not 674

#!/bin/ksh
#setup tns to point to oracle wallet
export TNS_ADMIN=/x01/user/oracle/product/11.2.0.4/wallet
export ORACLE_HOME=/x01/user/userhome/oracle/product/11.2.0.4
ORACLE_SID=NAME_OWNER
PATH=$ORACLE_HOME/bin PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
ORACLE_HOME/network/lib
export LIBPATH=($LD_LIBRARY_PATH):/user/lib:/lib
export ORACLE_HOME ORACLE_SID PATH
sqlplus /@NAME_OWNER<<EOF
exec runstoredproc;
exit
EOF
PATH=$PATH:/usr/bin
export PATH
chmod 664 /x01/data/dataextract/nameextract.txt
PATH=$ORACLE_HOME/bin PATH

should be

PATH=$ORACLE_HOME/bin:$PATH

I would consider two things

1. try to diagnose your chmod problem
    a. it is caused by by the accidental insertion of an unprintable character in your script 
       ex: cat -v myscript.sh  
       shows unprintable garbage characters
    b. something trashes your PATH variable - display your PATH variable after each step in the script
2. consider try running your chmod statement  with the env command:
   /usr/bin/env chmod 664 /x01/data/dataextract/nameextract.txt

Based on your code example, be sure to test each line of code independently if possible - simply for omission of stuff like the colon above.
set and env commands can help you see what your environment looks like at any point in your script.

1 Like

Thanks Jim . There was a junk character in the script which was causing this issue . This has now been corrected and script has completed successfully. Thanks for your help .

1 Like