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


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
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
Code:
#!/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
Code:
+-----------------------------------------------------------------------------------------------
+ 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

Last edited by Scrutinizer; 4 Days Ago at 02:42 PM.. Reason: icode tags to code tags + extra code tags
# 3  
Sorry Bad cut and Paste
Code:
#!/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

Moderator's Comments:
Mod Comment Please use [code]...[/code] tags instead of [icode]...[/icode] tags for multiline code and data samples

Last edited by Scrutinizer; 4 Days Ago at 05:08 AM.. Reason: icode -> code tags
# 4  
Looks like java is missing from PATH, does not exist on system or not properly installed.

Can you show output from :
Code:
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.
# 5  
The output of
Code:
 echo  "+ The IC_HOME variable is defined as ${IC_HOME} "

produces
Code:
  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:
Code:
echo "+ Next Check for jar ${IC_HOME}/lib/taleo-integrationclient.jar "

produces the output:
Code:
/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:

Code:
tr -d '\r' < file > newfile


Last edited by Scrutinizer; 4 Days Ago at 06:03 AM..
This User Gave Thanks to Scrutinizer For This Post:
# 6  
Thank you very much

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
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Setting environment variables from a file :
qwertyu
Hi, I have around 10 environment variables in my shell script. i want to set this all in a file and just call that file in my shell script. How can i do that ? Please help. TIA!... Shell Programming and Scripting
6
Shell Programming and Scripting
Using Datastage environment variables in Unix script
bghosh
Hi All, I am using ETL tool Datastage and is installed on Linux environment. Few environment variables are set in datastage. Now my requirement is to use those environment variables in a unix script. Is there any option I can do it? Sugeestions from people working on datastage and linux...... Shell Programming and Scripting
1
Shell Programming and Scripting
environment variables in a sed script file
edgarvm
Hello Everyone I need to create a script file which must append some lines to a target text file, I'm using sed for windows, the script file look like this: { a\ STRINGTABLE DISCARDABLE\ BEGIN\ 5, 150 {a\ #define RC_SHELL, "%ID_SHELL%"\ #define RC_NAME, "%ID_NAME%"\ END } ...... Shell Programming and Scripting
1
Shell Programming and Scripting
Problem setting environment variables from script
ruben.rodrigues
Hi all! I know that environment variables can be set on the .bashrc file, but I need to set them from a sh script. I saw a lot of websites that teach this but it doesn't work for me. #!/bin/sh DEKTOP=$DESKTOP=:/home/rrodrigues/Desktop export DESKTOP if I do echo $DESKTOP returns me...... Emergency UNIX and Linux Support
10
Emergency UNIX and Linux Support
how to expand environment variables in a file?
debbie15
I am new to unix and would appreciate if someone could help. I have an environment variable SourceFilePath=/db1/Src/test set on the unix server. I want to expand this SHELL variable in a file using any command sed, awk etc File contents is as follows: var=$SourceFilePath/file.txt ...... UNIX for Dummies Questions & Answers
2
UNIX for Dummies Questions & Answers

Featured Tech Videos