write applications outputs to mysql database with linux script

Can anyone tell me how to write the outputs of an application to mysql using bash script? for example a java application with the following code

class HelloWorld {
public static void main(String[] args) {
    System.out.println("Hello World!");
    System.out.println("Message 1!");
    System.out.println("Message 2!");
    System.out.println("Message 3!");
}

}

i want to produce 4 rows in table for every System.out

i tried that script

app_name="HelloWorld"
app_output=$(java $app_name);
mysql -u<username> -p'<password>' <db_name> <<_EOF_
INSERT INTO logs_tbl (app_name,text) VALUES ("$app_name","$app_output");
_EOF_

but the problem is that it produce one row when the app exit with value: Hello World!Message 1!Message 2!Message 3!

Answers


Try the following:

#!/bin/bash

app_name="HelloWorld"
java $app_name | while read line
do
        echo "INSERT INTO logs_tbl (app_name,text) VALUES ('$app_name','$line');" | mysql -u <username> -p '<password>' <db_name>
done

Need Your Help

What should I compare google play subscription expiry time to?

android api rest google-play-services google-play-developer-api

So, I am implementing a mechanism for validating Google Play suubscriptions.

C# Event Passing/Bubble Up

c# .net events

I subscribe to an Event inside a class. Such as