Find the answer to your Linux question:
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 ...
  1. #1
    Just 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)

    #retrieve the archive mode status
    archive_log_status=`cat archivelogstatus.txt`
    echo $archive_log_status
    if "$archive_log_status" = "ARCHIVELOG"
    then
    echo "ArchiveMode"
    fi
    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

    ./create_hot_backup_script_new.sh: line 114: ARCHIVELOG : command not found
    Im just trying to check the status if my database is in archive mode
    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

  2. #2
    Just Joined!
    Join Date
    Dec 2007
    Posts
    2

    Smile

    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

  3. #3
    Just 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

  4. #4
    scm
    scm is offline
    Linux 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:
    Code:
    if [ "$archive_log_status" = "ARCHIVELOG" ]
    This, unlike your version, will return false if the strings aren't equal.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...