UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 5th, 2006, 09:19 AM
scooterp83 scooterp83 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 206 scooterp83 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 57 m 12 sec
Reputation Power: 6
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:
PROG_NAME=com.cvs.backend.ccauth.CCAuth


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

Reply With Quote
  #2  
Old July 5th, 2006, 09:42 AM
vlsimpson vlsimpson is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Location: The grassy knoll
Posts: 115 vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 5 Days 2 h 1 m 30 sec
Reputation Power: 41
source the variable file at the top of your script.

Bash Code:
Original - Bash Code
  1. #!/bin/sh
  2. . variable-config file # That's a period there, source builtin is same thing: source variable-file
  3. the rest of your code

Reply With Quote
  #3  
Old July 5th, 2006, 09:50 AM
scooterp83 scooterp83 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 206 scooterp83 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 57 m 12 sec
Reputation Power: 6
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:
PROG_NAME=com.cvs.backend.ccauth.CCAuth
PROG_ARG=/cvsweb/batch/uat/holdprops/prop
ERR_LOG=ccauth
DATE=`date +%m%d`

Reply With Quote
  #4  
Old July 5th, 2006, 10:08 AM
vlsimpson vlsimpson is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Location: The grassy knoll
Posts: 115 vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 5 Days 2 h 1 m 30 sec
Reputation Power: 41
Yep.

Reply With Quote
  #5  
Old July 5th, 2006, 10:09 AM
scooterp83 scooterp83 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 206 scooterp83 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 57 m 12 sec
Reputation Power: 6
thanks alot i appreciate it

Reply With Quote
  #6  
Old July 5th, 2006, 11:11 AM
scooterp83 scooterp83 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 206 scooterp83 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 57 m 12 sec
Reputation Power: 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:
bash-2.03$ sh sh-test.sh
sh-test.sh: variable-config.prop^M: not found
bash-2.03$



However, here is my directory listing:

Quote:

bash-2.03$ ls
variable-config.prop sh-test.sh


Any ideas?

thanks

Reply With Quote
  #7  
Old July 5th, 2006, 11:36 AM
vlsimpson vlsimpson is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Location: The grassy knoll
Posts: 115 vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 5 Days 2 h 1 m 30 sec
Reputation Power: 41
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

Reply With Quote
  #8  
Old July 5th, 2006, 12:37 PM
Ehlanna's Avatar
Ehlanna Ehlanna is offline
Not a clue what to put ...
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: in front of this keyboard
Posts: 815 Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level)Ehlanna User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 5 h 43 m 48 sec
Reputation Power: 243
Sounds more like the script was edited in a Windows environment, then copied to Unix - a dos2unix inputfile > outputfile will sort that out.
Comments on this post
vlsimpson agrees: Very late but well-deserved rep
__________________
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?
.

Reply With Quote
  #9  
Old July 5th, 2006, 01:02 PM
vlsimpson vlsimpson is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Location: The grassy knoll
Posts: 115 vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level)vlsimpson User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 5 Days 2 h 1 m 30 sec
Reputation Power: 41
Your right, could be a ctrl-m on the end of the line in his script, but either way will futz it up.

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Importing variables into Unix Shell Script


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT