Attempting to GREP details of a Java error
        Posted  
        
            by 
                BOMEz
            
        on Ask Ubuntu
        
        See other posts from Ask Ubuntu
        
            or by BOMEz
        
        
        
        Published on 2012-06-20T14:49:30Z
        Indexed on 
            2012/06/20
            15:25 UTC
        
        
        Read the original article
        Hit count: 295
        
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
© Ask Ubuntu or respective owner