Challenge with sh script using environment variables to check for file.

Hi All
Thanks for reviewing my question.
I have a sh script where I used an environmental variable for the directory for the file I need to check to ensure before executing a process.
I have confirmed the permissions and I can find the file if I use a hard coding of the directory. This is a Centos 7 distribution.

Here is the script below

#!/bin/sh

# Make sure that the JAVA_HOME variable is defined
if  [ ! "${JAVA_HOME}" ]
then
    echo +-----------------------------------------+
    echo "+ The JAVA_HOME variable is not defined.  +"
    echo +-----------------------------------------+
    exit 1
else
	echo +-----------------------------------------------------------------------------------------------
    echo "+ this is Java Home ${JAVA_HOME}"
    echo +-----------------------------------------------------------------------------------------------	
fi

# Make sure the IC_HOME variable is defined
if  [ ! "${IC_HOME}" ]
then
    IC_HOME=.
	echo +-----------------------------------------------------------------------------------------------
    echo "+had to set IC_HOME"
    echo +-----------------------------------------------------------------------------------------------
else
	echo +-----------------------------------------------------------------------------------------------
    echo "+ The IC_HOME variable is defined as ${IC_HOME} "
	echo "+ Next Check for jar ${IC_HOME}/lib/taleo-integrationclient.jar "
    echo +-----------------------------------------------------------------------------------------------
fi

# Check if the IC_HOME points to a valid taleo Connect Client folder
if [ -e  ]
then
    # Define the class path for the client execution
    IC_CLASSPATH="${IC_HOME}/lib/taleo-integrationclient.jar":"${IC_HOME}/log"

    # Execute the client
   
    echo +-----------------------------------------------------------------------------------------------
    echo "+ The IC_HOME variable is defined as ${IC_HOME} "
    echo "+	but does not contain the Taleo Connect Client"
    echo "+ The library ${IC_HOME}/lib/taleo-integrationclient.jar cannot be found.                      "
    echo +-----------------------------------------------------------------------------------------------
    exit 2
fi

The response from running the script

+-----------------------------------------------------------------------------------------------
+ this is Java Home /usr/lib/jvm/jre
+-----------------------------------------------------------------------------------------------
+-----------------------------------------------------------------------------------------------
  The IC_HOME variable is defined as /opt/huronesb/taleoccc/tcc-19.2.0.3
/lib/taleo-integrationclient.jar b/taleoccc/tcc-19.2.0.3
+-----------------------------------------------------------------------------------------------
/bin/java: No such file or directorytest.sh: line 37: /usr/lib/jvm/jre

I am just looking for guidance as to where to look.

Thanks

Robert Stojkovic

Hi, this one is missing a filename:

if [ -e  ]

Sorry Bad cut and Paste

#!/bin/sh

# Make sure that the JAVA_HOME variable is defined
if  [ ! "${JAVA_HOME}" ]
then
    echo +-----------------------------------------+
    echo "+ The JAVA_HOME variable is not defined.  +"
    echo +-----------------------------------------+
    exit 1
else
	echo +-----------------------------------------------------------------------------------------------
    echo "+ this is Java Home ${JAVA_HOME}"
    echo +-----------------------------------------------------------------------------------------------	
fi

# Make sure the IC_HOME variable is defined
if  [ ! "${IC_HOME}" ]
then
    IC_HOME=.
	echo +-----------------------------------------------------------------------------------------------
    echo "+had to set IC_HOME"
    echo +-----------------------------------------------------------------------------------------------
else
	echo +-----------------------------------------------------------------------------------------------
    echo "+ The IC_HOME variable is defined as ${IC_HOME} "
	echo "+ Next Check for jar ${IC_HOME}/lib/taleo-integrationclient.jar "
    echo +-----------------------------------------------------------------------------------------------
fi

# Check if the IC_HOME points to a valid taleo Connect Client folder
if [ -e  "${IC_HOME}/lib/taleo-integrationclient.jar" ]
then
    # Define the class path for the client execution
    IC_CLASSPATH="${IC_HOME}/lib/taleo-integrationclient.jar":"${IC_HOME}/log"

    # Execute the client
   
    echo +-----------------------------------------------------------------------------------------------
    echo "+ The IC_HOME variable is defined as ${IC_HOME} "
    echo "+	but does not contain the Taleo Connect Client"
    echo "+ The library ${IC_HOME}/lib/taleo-integrationclient.jar cannot be found.                      "
    echo +-----------------------------------------------------------------------------------------------
    exit 2
fi

Looks like java is missing from PATH, does not exist on system or not properly installed.

Can you show output from :

echo $PATH
which java
ls -dl /usr/lib/jvm/jre/bin/java

From the shell with user executing your script.
Please use CODE tags, not ICODE for such large code portions.

Regards
Peasant.

The output of

 echo  "+ The IC_HOME variable is defined as ${IC_HOME} "

produces

  The IC_HOME variable is defined as /opt/huronesb/taleoccc/tcc-19.2.0.3

Note the two leading spaces, The first space is what used to be the + character and it is overwritten by the space after the ${IC_HOME} variable expansion.
This indicates a trailing carriage return character in the IC_HOME variable

Then:

echo "+ Next Check for jar ${IC_HOME}/lib/taleo-integrationclient.jar "

produces the output:

/lib/taleo-integrationclient.jar b/taleoccc/tcc-19.2.0.3

Also here part of the text gets overwritten. /lib/taleo-integrationclient.jar ends up at the beginning of the line.

So again this indicates a trailing carriage return character in the IC_HOME variable.

My guess this variable is being set by another script and that this scripts contains CR-LF (Carriage Return + Line Feed) at the end, so it is in Windows format. It needs to be converted to Unix format (only a LF, no CR).

Convert the script in which the IC_HOME variable is set to Unix format like so:

tr -d '\r' < file > newfile
1 Like

I reviewed the environment file and found that it had the LF after the variable.
I corrected the issue and now the script can find with the variable and the hard coded.

Appreciate your help with this.

Thanks
Robert