Attempting to GREP details of a Java error
- by BOMEz
I'm running Ubuntu 11 and I'm having some issues with grep.
I have a shell script (see below) which essentially checks if a certain Java program of mine is running, if not it runs it. That part works out great!
If my Java application throws any kind of exception however I would like to capture that information and email it to myself. How can I go about checking to see if the call to java -jar /bin/MyApp.jar fails? I tried piping it to grep, but that doesn't seem to work.
Below is the full script that I've written:
#Check if MyApp.jar is running, if not run it.
if [ $(ps aux | grep 'java' | grep -v grep | wc -l | tr -s "\n") -eq 0 ]
then
echo "PacketCapture Starting...\n"
java -jar /bin/MyApp.jar
echo "PacketCapture Started.\n"
else
echo "PacketCapture already running.\n"
fi