Today a co-worker asked me how to get the value of a configuration entry from a java properties file. For this purpose
cut does a splendid job.
We cut the line with delimiter = and retrieve the second field.
echo "logfile=/var/log/java/msl.log" | cut -f2 -d= /var/log/java/msl.log
He needed the log filename to append a log message to it. Simply killing a Java process, is not the desired way, but if you aren’t the vendor of that particular software, you go for it. The application itself does not or can’t write any details into the log file. Thats why he is appending a log message to the logfile. To be logstash compliant to my configuration, the format should be maintained. We using date to create a compliant timestamp format.
echo "$(date +%Y-%m-%d\ %H:%M:%S),000 [Control-M] INFO (control-m-agent) Shutdown connector" 2015-12-22 15:47:42,000 [Control-M] INFO (control-m-agent) Shutdown connector
The whole code used in a bash script.
LOGFILE=$(cat app.properties | grep logfile | cut -f2 -d= ) echo "$(date +%Y-%m-%d\ %H:%M:%S),000 [Control-M] INFO (control-m-agent) Shutdown connector" >> $LOGFILE