Find the answer to your Linux question:
Results 1 to 6 of 6
Hi Guys, I need a help. I write a script that gives me the recently backed-up ear file. Command is : ls -1t *.ear*-EDT-* | head -1 Now, i want ...
  1. #1
    Just Joined!
    Join Date
    Aug 2007
    Posts
    18

    Question Bash Script

    Hi Guys,

    I need a help. I write a script that gives me the recently backed-up ear file.
    Command is :

    ls -1t *.ear*-EDT-* | head -1

    Now, i want to implement a if-then-else clause for checking the ear and display a message.

    Can anyone tell me how I can do it.

  2. #2
    Just Joined!
    Join Date
    Oct 2007
    Posts
    37
    What exactly is it checking for?

    For example, if the file exists:

    if [ -f /path/to/file ]; then
    echo $file exists!;
    fi;

  3. #3
    Just Joined!
    Join Date
    Aug 2007
    Posts
    18

    Question

    Thanks a lot but tell me one more thing.
    there is a file named "um.ear" and more than two files named "um.ear-Tue-Aug_08_16:14:25-EDT-2006" exist in the following path:
    /usr/local/PServer41/server/nodes/My_Node

    and I have to run the script from the following :
    /usr/local/PServer41/server/nodes/My_Node/Maintenance

    I am using the following for "um.ear-Tue-Aug_08_16:14:25-EDT-2006" file to get the latest file

    if [ `ls -1t *.ear*-EDT-* | head -1` == "" ]
    then
    echo "No EAR found"
    fi

    Then I got the error "unary operator expected"

    Please help me how I can solve it

  4. #4
    Just Joined!
    Join Date
    Oct 2007
    Posts
    37
    Try this instead:

    Code:
    earfile=`ls -latro | grep "um.ear-" | head -1`;
    if [ -z "$earfile" ]
    then
    echo "No EAR found"
    else
    echo "FOUND!"
    fi

    The error was due to it not finding the file and the way the condition was written.

  5. #5
    Just Joined!
    Join Date
    Aug 2007
    Posts
    18

    Smile BASH Script Contd...

    It's working.

    Thanks a lot.

  6. #6
    Just Joined!
    Join Date
    Oct 2007
    Posts
    37
    You're welcome.

Posting Permissions

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