#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    How to recetify the error in if loop by using unix?


    Hi,

    Please help me to find the out the error in the below script:

    GENHOME=/appbin/gentran/gis43/logs
    LOG_DAYS=7
    current_date=`date '+%h %d'`

    # Start

    #Lists the core dump of last seven days

    echo "*************************************************"
    echo "List of core dumps for last seven days"
    echo "*************************************************"
    find $GENHOME -name "noapp.log.*" -mtime -$LOG_DAYS -ls | awk '{print $8,$9,$10}' | sort | grep -v "$current_date" > core_dump;
    cat core_dump
    if [-z $core_dump];
    then
    echo "*************************************************"
    echo "No core dumps over the week"
    echo "*************************************************"
    fi

    echo "================================================================================="

    #Lists the gentran application restart timings
    echo "*************************************************"
    echo "List of application restart for last seven days"
    echo "*************************************************"
    find $GENHOME -name "hardstop.sh.log" -mtime -$LOG_DAYS -ls | awk '{print $8,$9,$10}' | sort | grep -v "$current_date" > app_restart;
    cat app_restart
    if [-z $app_restart];
    then
    echo "*************************************************"
    echo "No application restart over the week"
    echo "*************************************************"
    fi
    #END

    I am getting the below output

    *************************************************
    List of core dumps for last seven days
    *************************************************
    Nov 12 22:59
    Nov 13 23:00
    Nov 14 23:00
    Nov 15 22:59
    Nov 16 22:59
    Nov 17 22:59
    Nov 18 23:00
    new.sh: [-z: not found
    =================================================================================
    new.sh: [-z: not found

    How to rectify the erro
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,376
    Rep Power
    1871
    > cat core_dump
    > if [-z $core_dump];
    Because you have a filename, not a variable name.

    So perhaps
    Code:
    cat core_dump
    if [-z core_dump];
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0

    Smile


    Still, i am getting the same error


    *************************************************
    List of core dumps for last seven days
    *************************************************
    Nov 13 23:00
    Nov 14 23:00
    Nov 15 22:59
    Nov 16 22:59
    Nov 17 22:59
    Nov 18 23:00
    Nov 19 22:59
    new.sh: [-z: not found
    =================================================================================
    *************************************************
    List of application restart for last seven days
    *************************************************
    new.sh: [-z: not found


    I like the quote 'If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut'
  6. #4
  7. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,376
    Rep Power
    1871
    Try some extra spaces
    if [ -z blah ];
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2010
    Posts
    8
    Rep Power
    0
    It is working now....Thanks for your time!

IMN logo majestic logo threadwatch logo seochat tools logo