Look for jar files that contain files which have a searched text

Problem:
It happened that one of the jar files in my local repository contains a file (presumably a log4j.xml or log4j.properties) which has a text: test.log. Find that jar file and the check if it was in log4j.xml or log4j.property).

Solution (bash script):


#!/bin/bash

#serch all jar files
for jar in $(find -name \*.jar); do

#for each jar, list all the log4j.xml or log4j.properties
files=$(unzip -l $jar | grep -i 'log4j\.[xml|properties]' | awk '{print $4}');

#iterate over found log4j.xml or log4j.properties
for file in $files; do

#check if the found file contains 'test.log'
if unzip -p $jar $file | grep -i 'test\.log'; then

#print the found jar and file name
echo " $jar $file ";
fi ;
done;
done;

Result (found):
log4j.appender.out.file=${basedir}/target/test.log
./org/apache/activemq/activeio-core/3.1.0/activeio-core-3.1.0-tests.jar log4j.properties

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s