0

Need help on this simple script... I am scratching my head...

when I do
echo $myhost
it returns db3

However, when running the script, the first IF condition is always true... what went wrong? Thanks!

Here is the script:

myhost=`hostname -s`

if [ $myhost='db1' ]; then
echo "###############################################"
echo "### Welcome to Site 1 ###"
echo "###############################################"

if [ -f /db2home/db2idev1/sqllib/db2profile ]; then
. /db2home/db2idev1/sqllib/db2profile
fi

elif [ $myhost='db2' ]; then
echo "###############################################"
echo "### Welcome to Site 2 ###"
echo "###############################################"

if [ -f /db2home/db2iuat1/sqllib/db2profile ]; then
. /db2home/db2iuat1/sqllib/db2profile
fi

elif [ $myhost='db3' ]; then
echo "####################################################"
echo "### Welcome to Site 3 ###"
echo "####################################################"

if [ -f /db2home/db2iprd1/sqllib/db2profile ]; then
. /db2home/db2iprd1/sqllib/db2profile
fi

else

echo "exit"
exit 1
fi

2
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by alc6379
0

i got it, take the ' ' out of the if condition....
for example
if [ $myhost = db1 ]; then
this works!

0

One thing I noticed, too, was that you are using = instead of == . = can assign values to a variable, whereas == checks for equality.

That might have something to do with it, too...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.