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 ...
- 10-21-2007 #1Just Joined!
- Join Date
- Aug 2007
- Posts
- 18
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.
- 10-21-2007 #2Just 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;
- 10-26-2007 #3Just Joined!
- Join Date
- Aug 2007
- Posts
- 18
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
- 10-26-2007 #4Just 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.
- 10-27-2007 #5Just Joined!
- Join Date
- Aug 2007
- Posts
- 18
BASH Script Contd...
It's working.
Thanks a lot.
- 10-28-2007 #6Just Joined!
- Join Date
- Oct 2007
- Posts
- 37
You're welcome.


Reply With Quote