|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Importing variables into Unix Shell Script
Hello, I was wondering if there was a way to import my variables into a Unix Shell script instead of having to hard code them into the .sh file. Here is part of the original shell script....
Code:
PROG_NAME=com.cvs.backend.ccauth.CCAuth
PROG_ARG=/cvsweb/batch/uat/holdprops/prop
ERR_LOG=ccauth
DATE=`date +%m%d`
echo "Starting CCAuth process ... "
JAVA_ARGS=" -Xmaxjitcodesize30000000 -DLOGPROPFILE=$LOGPROPFILE -DHoldPropsHostAndPort0=suncdcd2:1505"
if [[ -f ${JAVA_HOME}/bin/java ]]; then
echo "We have java installed!"
! ${JAVA_HOME}/bin/java -classpath $CLASSPATH $JAVA_ARGS $PROG_NAME
if [[ $? -eq 1 ]]; then
echo "Java program $PROG_NAME executed successfully!"
return 0
else.............
This script is used on many different enviornments and we would like to only use one script. However, the variable: Quote:
Changes for each enviornment. therefore it would be easier if we had a properties file that stored all of these variables and we could change the properties file without having to touch the shell script. Is there a way to import the properties file and then used the variables dynamically so we dont have to have 5 different shell scripts? Thanks |
|
#2
|
|||
|
|||
|
|
|
#3
|
|||
|
|||
|
So basically if my properties file is variables.prop all i have to do is the following:
Code:
#!/bin/sh
. variables.prop
echo "Starting CCAuth process ... "
JAVA_ARGS=" -Xmaxjitcodesize30000000 -DLOGPROPFILE=$LOGPROPFILE -DHoldPropsHostAndPort0=suncdcd2:1505"
if [[ -f ${JAVA_HOME}/bin/java ]]; then
echo "We have java installed!"
! ${JAVA_HOME}/bin/java -classpath $CLASSPATH $JAVA_ARGS $PROG_NAME
if [[ $? -eq 1 ]]; then
echo "Java program $PROG_NAME executed successfully!"
return 0
else.............
And i can take out the following variables because they are already defined in the variable.prop file? Quote:
|
|
#4
|
|||
|
|||
|
Yep.
|
|
#5
|
|||
|
|||
|
thanks alot i appreciate it
|
|
#6
|
||||
|
||||
|
I just tried a simple script to see if this works. in the current directory i have 2 files. sh-test.sh and variable-config.prop.
sh-test.sh Code:
#!/usr/bin/ksh . variable-config.prop echo $ERR_LOG variable-config.prop Code:
ERR_LOG=ccauth When i run the following command: sh sh-test.sh I GET THE FOLLOWING: Quote:
However, here is my directory listing: Quote:
Any ideas? thanks |
|
#7
|
|||
|
|||
|
It looks like you got a Ctrl-M character tacked on to the file name somehow.
Rename it (use the tab key to complete out the first arg and then type the full name again) Code:
mv variable-config.prop^M variable-config.prop |
|
#8
|
||||
|
||||
|
Sounds more like the script was edited in a Windows environment, then copied to Unix - a dos2unix inputfile > outputfile will sort that out.
__________________
According to Sod's Law, buttered toast lands butter side down, when dropped. Per nature, cats always land on their feet. So, what happens when you strap buttered toast to the back of a cat and throw it out a window?. |
|
#9
|
|||
|
|||
|
Your right, could be a ctrl-m on the end of the line in his script, but either way will futz it up.
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Importing variables into Unix Shell Script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|