Execution of shell script returns error 127

Hi All,

While running shell script i got following output.

interpreter "usr/bin/ksh" not found
sh: step1.sh: not found.
ldnhpux | oracle >echo $?
127

  • - Running command "which ksh" retruns "usr/bin/ksh".
  • - I found some information on web stating to remove extra carriage return chars, To achieve that I tried using cat and sed commands. Did not work though.
  • - I tried ftp the file in ASC mode. No luck.

Any ideas ?:confused:

Regards

Can you post

  1. Permission given to the script
  2. How did you execute the script in command line. (./scriptname or sh scriptname etc)
  3. Contents of the script.
1. -rwxrwxrwx   1 oracle     oinstall      3318 Aug 17 19:00 step1.sh

2. >step1.sh <parameters>

3. ======================================================
#!usr/bin/ksh
#set -x
################################################################################
# Script to extract Package Body, Function and Procedure source from Database and to create ORA file for each object.
# 
#################################################################################

# Set the variables to be used

# Specify the location where the wrap folder is created
wrappath=/acc/NATDUB11/wrapping
binPath=/usr/bin
logDir=${wrappath}/logs
objectDir=${wrappath}/objects
utilityDir=${wrappath}/utility
plbDir=${wrappath}/plb
listSQLFile=${utilityDir}/listFCUBS.sql
extractSQLFile=${utilityDir}/extractFCUBS.sql

listFile=${logDir}/filelistFCUBS.txt
extractlogFile=${logDir}/extractFCUBS.log

${binPath}/rm -f ${listFile} ${extractlogFile}
echo "Existing files removal done" >>${extractlogFile}

echo "##################STEP1 starts for ${2}##################"
echo "##################STEP1 starts for ${2}##################" >>${extractlogFile}

echo "Variables set"  >>${extractlogFile}

# Set Oracle Home
ORACLE_HOME=/ora9i/app/oracle/product/9.2.0.1.0
export ORACLE_HOME
errVal=1
successVal=0

# Preliminary checks
if [ $# -ne 2 ]
then
    ${binPath}/echo "Error: Incorrect Number of Parameters" >&2
    ${binPath}/echo "USAGE: $0 <dbusername>/<dbpassword>@<db schemaname> < dbusername >" >&2
    echo "Error: Incorrect Number of Parameters" >>${extractlogFile}
    exit ${errVal}
fi

if test ! -s ${listSQLFile} 
then
    ${binPath}/echo "Error: Cannot find List SQL file - ${listSQLFile}" >&2
    echo "Error: Cannot find List SQL file - ${listSQLFile}" >>${extractlogFile}
    exit ${errVal}
fi

if test ! -s ${extractSQLFile}
then
    ${binPath}/echo "Error: Cannot find Extract SQL file - ${extractSQLFile}" >&2
    echo "Error: Cannot find Extract SQL file - ${extractSQLFile}" >>${extractlogFile}
    exit ${errVal}
fi

echo "Preliminary checks done"
echo "Preliminary checks done" >>${extractlogFile}

# Fetch the list of objects
${ORACLE_HOME}/bin/sqlplus -l -s ${1} @${listSQLFile} ${2}>${listFile};<<EOF
exit;
EOF

echo "Fetched object names and type details, ${listFile} created"
echo "Fetched object names and type details, ${listFile} created" >>${extractlogFile}


# Fetch the object source and create the respective file for each object
echo "Extracting sources..."
while read inputlistfile
do
    ObjectName="$(${binPath}/echo $inputlistfile | ${binPath}/cut -f1 -d',')"
    ObjectType="$(${binPath}/echo $inputlistfile | ${binPath}/cut -f2 -d',')"
    #echo ${ObjectName} '~~~' ${ObjectType}
    echo "Extacting source for ${ObjectName} ${ObjectType}">>${extractlogFile}
    ${ORACLE_HOME}/bin/sqlplus -l -s ${1} @${extractSQLFile} ${2} ${ObjectName} "${ObjectType}">>${extractlogFile};
    #exit;
done <${listFile}
echo "Source extraction done"
echo "Source extraction of the objects done into ${objectDir} as LST files" >>${extractlogFile}

# Rename the lst file as ora file in the objects directory
cd ${objectDir}
for f in *.lst ; 
do
    mv $f `basename $f lst`ora; 
done

echo "ORA Files created in " ${objectDir}
echo "Files renamed as ORA files in "${objectDir} >>${extractlogFile}

cd ${utilityDir}

echo "Extraction Done"
echo "Extraction Done" >>${extractlogFile}

echo "##################STEP1 ends for ${2}##################"
echo "##################STEP1 ends for ${2}##################" >>${extractlogFile}
======================================================

Thanks

Can you try executing the script as ./step1.sh <parameters> from the command line.. ?

[LEFT]Same Error.
[/LEFT]

Ok. Try as sh step1.sh <parameters> If you still get the same error then IMO you would need to include your script's path/location in the PATH variable. Or did you copy the file from windows to unix box..? Post few lines of output from cat -v filename . If you find control characters in the output then that should be the issue. Removing the control chars would resolve.

1 Like

Awesome, Its Running now. Hope it will finishes successfully.
Can you please tell me what difference does it make if we use sh ?

The shebang was wrong. It should be as #!/usr/bin/ksh . If you run the script with ksh scriptname we explicitly asking k shell to run the script. Similarly it could be as sh scriptname where bash shell runs the script. Since the shebang was not correct in your original file you got the error.

I think 'sh' will tell the processor what compilor it is going to use..
One more thing, in the first line where you put "#!usr/bin/ksh" i think you need to add one more slash
it should be like
#!/usr/bin/ksh