Results 1 to 5 of 5
I give up. I didn't want to ask for help on this, but this is driving me crazy.
I've written an auto-installer for my application. Here it is:
Code:
#!/bin/bash
...
- 06-02-2009 #1Just Joined!
- Join Date
- Jun 2009
- Location
- Florida
- Posts
- 3
Bash scripting with variables - I miss DOS (I am a noob)
I give up. I didn't want to ask for help on this, but this is driving me crazy.
I've written an auto-installer for my application. Here it is:
These last two lines will not work, no matter what I try, in a script. If I type them in by hand, at the command line, they work fine. Essentially I'm simply grepping for a known value in two files, and trying to replace them with bash variables that have been set during bootup.Code:#!/bin/bash #Update an existing install clear echo "Copying tar file from devbuild server - enter pwd:" scp 100.11.184.12:/app/blah0.5.tar /tmp echo "Unzipping blah0.5.tar, overlaying current /app/blah code layer..." cd / tar -xzvf /tmp/blah0.5.tar echo "Done installing new blah source - running config..." echo $Branch_Server echo $Store_Number sed -i 's/odsblahdev01/'"$Branch_Server"'/g' /app/blah/Store\ Server/stop_jboss.sh sed -i 's/store.number=8001/store.number='"$Store_Number"'/g' /app/blah/blah.properties
I've tried:
sed -i 's/store.number=8001/store.number="$Store_Number"/g /app/blah/blah.properties
sed -i "s/store.number=8001/store.number=$Store_Number/g" /app/blah/blah.properties
sed -i 's/store.number=8001/store.number=$Store_Number/g' /app/blah/blah.properties
and several other minor variations... i give up!?! Any idea what i'm doing wrong? Thanks in advance for your help!
JP
- 06-02-2009 #2Where are these values set? if that is the entirety of your script, they are never set. Also I would recommend when using them in the sed script to write them as such ${Branch_Server} and ${Store_Number}.Code:
echo $Branch_Server echo $Store_Number
- 06-02-2009 #3Just Joined!
- Join Date
- Jun 2009
- Location
- Florida
- Posts
- 3
I've tried putting the variables in {}, that didn't work either.
The variables are being set in bash.bashrc.local:
Code:oct1=`ifconfig eth0 | awk '/inet addr/ {split ($2,A,":"); print A[2]}' | awk '/./ {split ($1,A,"."); print A[1]}'` oct2=`ifconfig eth0 | awk '/inet addr/ {split ($2,A,":"); print A[2]}' | awk '/./ {split ($1,A,"."); print A[2]}'` oct3=`ifconfig eth0 | awk '/inet addr/ {split ($2,A,":"); print A[2]}' | awk '/./ {split ($1,A,"."); print A[3]}'` oct4=`ifconfig eth0 | awk '/inet addr/ {split ($2,A,":"); print A[2]}' | awk '/./ {split ($1,A,"."); print A[4]}'` oct3vl=$((($oct3)+128)) Branch_Server=$oct1.$oct2.$oct3.$oct4 Branch_Subnet=$oct1.$oct2.$oct3. Branch_VL=$oct1.$oct2.$oct3vl. JBOSS_HOME=/opt/jboss-4.0.5.GA CANDLEHOME=/opt/IBM/ITM Store_Number=`awk '{print $0}' /opt/OD/Build_Scripts/bld_StrNum` ImgVer=`cat /opt/OD/Build_Scripts/log/bld_ImageVer |grep BrchSrv`
- 06-02-2009 #4
does the echo on those variables produce the expected output when you run your script? if not you should source those bash files with . at the top of your script
- 06-02-2009 #5Just Joined!
- Join Date
- Jun 2009
- Location
- Florida
- Posts
- 3
That did it, thanks! I added:
. /etc/bash.bashrc.local
to the top of my script, and it's working fine now. Thanks!


Reply With Quote
