Results 1 to 4 of 4
im trying to test the part of the code, using simple if condition statement, please see code below (im having a trouble - im not that really good in shell ...
- 12-14-2007 #1Just Joined!
- Join Date
- May 2007
- Posts
- 7
bash script issue
im trying to test the part of the code, using simple if condition statement, please see code below (im having a trouble - im not that really good in shell scripting)
When I'm trying to execute the script I encounter error, can you help me understand if I have code error (or mistakes)?. My error is#retrieve the archive mode status
archive_log_status=`cat archivelogstatus.txt`
echo $archive_log_status
if "$archive_log_status" = "ARCHIVELOG"
then
echo "ArchiveMode"
fi
Im just trying to check the status if my database is in archive mode./create_hot_backup_script_new.sh: line 114: ARCHIVELOG : command not found
and it seems that the shell environment interpret the string as command, which should not be, because im just trying to check the variable value.
any help is really appreciated.
thanks in advance
- 12-14-2007 #2Just Joined!
- Join Date
- Dec 2007
- Posts
- 2
Hi,
I think the "if" syntax is wrong. just try to use the below syntax and hope it will work fine...
if [ "$archive_log_status" = "ARCHIVELOG" ]
Regards,
Muthukumar.AL
- 12-19-2007 #3Just Joined!
- Join Date
- May 2007
- Posts
- 7
Thanks for the reply,
but i fixed it through just simple trial and error
by just removing the space (sigh..) i never knew thats the main reason, i been trying a lot of testing the modifying the code..
the whole code will be
#!/bin/bash
archive_log_status=`cat archivelogstatus.txt`
echo $archive_log_status
if [ "$archive_log_status"=="ARCHIVELOG" ]
then
echo "ArchiveMode"
else
echo "Not in Archive Mode"
fi
Note: Just remove space in the archive_log_status variable before and after equal character. And remove the space between two equal sign in the line in the if statement
- 12-20-2007 #4Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
Does your script ever echo "Not in Archive Mode"? Looks to me that your test will always be true. If you're comparing strings you must put spaces around the comparison operator:
This, unlike your version, will return false if the strings aren't equal.Code:if [ "$archive_log_status" = "ARCHIVELOG" ]


Reply With Quote