njafri
January 29, 2010, 12:18pm
1
I Have a script which gets the status of oracle database and if the status is READ WRITE ..it should echo "db is up " else "db is down"
Here is the code
if [ "$status" = "READ WRITE" ]
then
echo "db up"
else
echo "db down"
fi
done;
The script is giving me out put "db down" even thoug the value of variable status is READ WRITE.
Try "==" and see if the space between READ and WRITE is indeed a space, not a tab or something.
njafri
January 29, 2010, 2:16pm
3
Tried putting "==" no progress. There is a space between "READ WRITE"
before 'if' put:
echo "x${status}x"
echo "xREAD WRITEx"
and see if they are the same.
njafri
January 29, 2010, 2:44pm
5
Hello Friend,
I think you reply was in the right direction to fix the problem in the code..This is what i am geting after echoing those 2 values
x{
READ WRITE}x
xREAD WRITEx
That means my variable $status has READ WRITE with some space on the front..thats why its unable to compare..can you please tell me how can i get rid of those spaces
Thankyou somuch for you help
See:
echo -e "bla\nbla" | tr -d '\n'
The following:
tr -d '\n'
will remove any newlines from input.
njafri
January 29, 2010, 3:08pm
7
I tried this..
what happens is if i run it on the command prompt (outside) script it works fine..But in the script its not removing spaces
echo -e " READ WRITE"|tr -d '\n'
READ WRITE
new_status=`echo -e "$status"|tr -s '\n'`
echo "x{$new_status}x"
echo "xREAD WRITEx"
x{-e READ WRITE}x
xREAD WRITEx
---------- Post updated at 12:08 PM ---------- Previous update was at 12:05 PM ----------
Buddy,
I removed the -e and it works wonders...Gr8 help i was struggling with this since morning