Extract/See content of a specific file inside a .war file - linux

I am trying to view the content of a file ( in linux )that is inside a .war file without having to extract the war file. For example inside the war file i am trying to see the content of a file called aa.txt and which is under /path/here/ inside the war file.

jar has x option for that:
$ jar -help 2>&1 | grep extract
-x extract named (or all) files from archive
Let's try it:
$ jar tvf target/my.war | grep test-data
1811 Tue Jun 21 19:34:50 CEST 2016 WEB-INF/classes/test/spring/test-data.properties
$ jar xvf target/my.war WEB-INF/classes/test/spring/test-data.properties
inflated: WEB-INF/classes/test/spring/test-data.properties
$ ls -l WEB-INF/classes/test/spring/test-data.properties
-rw-rw-r--. 1 coder coder 1811 Jun 21 19:34 WEB-INF/classes/test/spring/test-data.properties

Related

java -xvf test.jar not working

i tried to extract the test.jar
command is executing successfully but no output.
user#host:home/test->ll
drwxr-xr-x 107 user abc 6040 Apr 4 09:55 ..
drwxr-xr-x 2 user abc 26 Apr 4 10:06 .
-rw-r--r-- 1 user abc 51241 Apr 4 10:06 test.jar
user#host:home/test->jar -xvf test.jar
user#host:home/test->ll
total 262
drwxr-xr-x 107 user abc 6040 Apr 4 09:55 ..
drwxr-xr-x 2 user abc 26 Apr 4 10:06 .
-rw-r--r-- 1 user abc 51241 Apr 4 10:06 test.jar
Kindly help me to resolve this
Actual Requirement:
Need to extract and access a resource in jar file.
According to Oracle Java toutorials:
https://docs.oracle.com/javase/tutorial/deployment/jar/unpack.html
You should unpack it with:
jar xfv test.jar
Without '-' sign.
x option indicates that you want to extract files from the JAR archive.
f options indicates that the JAR file from which files are to be extracted is specified on the command line, rather than through stdin.
v is verbose
try to this command also unzip test.jar and below commands help you view some file without extract all the files.
unzip -q -c test.jar META-INF/MANIFEST.MF

Script that calls another script to execute on every file in a directory

There are two directories that contains these files:
First one /usr/local/nagios/etc/hosts
[root#localhost hosts]$ ll
total 12
-rw-rw-r-- 1 apache nagios 1236 Feb 7 10:10 10.80.12.53.cfg
-rw-rw-r-- 1 apache nagios 1064 Feb 27 22:47 10.80.12.62.cfg
-rw-rw-r-- 1 apache nagios 1063 Feb 22 12:02 localhost.cfg
And the second one /usr/local/nagios/etc/services
[root#localhost services]$ ll
total 20
-rw-rw-r-- 1 apache nagios 2183 Feb 27 22:48 10.80.12.62.cfg
-rw-rw-r-- 1 apache nagios 1339 Feb 13 10:47 Check usage _etc.cfg
-rw-rw-r-- 1 apache nagios 7874 Feb 22 11:59 localhost.cfg
And I have a script that goes through file in Hosts directory and paste some lines from that file in the file in the Services directory.
The script is ran like this:
./nagios-contacts.sh /usr/local/nagios/etc/hosts/10.80.12.62.cfg /usr/local/nagios/etc/services/10.80.12.62.cfg
How can I achieve that another script calls my script and goes through every file in the Hosts directory and does its job for the files with the same name in the Service directory?
In my script I´m pulling out contacts from the 10.80.12.62.cfg in the Hosts directory and appending them to the file with the same name in the Service directory.
Don't use ls output as an input to for loop instead use the built-in wild-cards. See why it's not a good idea.
for f in /usr/local/nagios/etc/hosts/*.cfg
do
basef=$(basename "$f")
./nagios-contacts.sh "$f" "/usr/local/nagios/etc/services/${basef}"
done
It sounds like you just need to do some iteration.
echo $(pwd)
for file in $(ls); do ./nagious-contacts.sh $file; done;
So it will loop over all files in the current directory.
You can also modify it as well by doing something more absolute.
abspath=$1
for file in $(ls $abspath); do ./nagious-contacts.sh $abspath/$file; done
which would loop over all files in a set directory, and then pass the abspath/filename into your script.

Zipping a folder in linux gives different size with different user

I have a folder which i want to create tgz file and compute its sha256:
The folder is converted to tgz using following command
"tar -c -C #{Shellwords.escape dir} #{Shellwords.escape basename} " \
"--owner=0 --group=0 --mtime='2000-01-01 00:00:00' | gzip -n > #{Shellwords.escape file}"
Now i ran the above process using 2 separate users and it gave me 2 files: 1 and 2
Both tgz files differ in sizes:
-rw-r--r--# 1 myuser \Domain Users 9024 Jul 31 14:28 1.tgz
-rw-r--r--# 1 myuser \Domain Users 9037 Jul 31 14:29 2.tgz
If i try to compute diff between files i dont see any diff.Diff was obtained using following command.
diff <(tar -tvf 1.tgz | sort) <(tar -tvf 2.tgz | sort)
If i compute sha256 using ruby of these 2 files , then it differs.
The question is : Why do i get difference in tgz files when running from different users.
the differences are in the headers, the header of each file in a tar contains the user and group id. see https://en.wikipedia.org/wiki/Tar_(computing)#Header .
Also modern tar adds additional data called Ustar to the header: https://en.wikipedia.org/wiki/Tar_(computing)#UStar_format
which contains also the owner username.
try:
diff <(gunzip -c 1.tgz | xxd) <(gunzip -c 1.tgz | xxd)
and you'll see the difference

Can't locate Spreadsheet/ParseExcel.pm in #INC though it's seems to be installed

Can't locate Spreadsheet/ParseExcel.pm in #INC (#INC contains: /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .)
though it's installed:
% perl -e'use CPAN; install "Spreadsheet:WriteExcel"'
Going to read '/home/aspect_mkn8rd/.cpan/Metadata'
Database was generated on Sun, 27 Apr 2014 09:41:02 GMT
Spreadsheet::WriteExcel is up to date (2.40).
That's where it located, yep?
% ls -la /usr/local/lib/perl/5.14.2/auto/Spreadsheet/WriteExcel
total 12
drwxrwxr-x 2 root root 4096 апр. 28 13:11 .
drwxrwxr-x 3 root root 4096 апр. 28 13:11 ..
-rw-rw-r-- 1 root root 2519 апр. 28 13:11 .packlist
% cat /usr/local/lib/perl/5.14.2/auto/Spreadsheet/WriteExcel/.packlist
/usr/local/bin/chartex
/usr/local/man/man1/chartex.1p
/usr/local/man/man3/Spreadsheet::WriteExcel.3pm
/usr/local/man/man3/Spreadsheet::WriteExcel::BIFFwriter.3pm
<..>
/usr/local/man/man3/Spreadsheet::WriteExcel::Workbook.3pm
/usr/local/man/man3/Spreadsheet::WriteExcel::Worksheet.3pm
/usr/local/share/perl/5.14.2/Spreadsheet/WriteExcel.pm
/usr/local/share/perl/5.14.2/Spreadsheet/WriteExcel/BIFFwriter.pm
/usr/local/share/perl/5.14.2/Spreadsheet/WriteExcel/Big.pm
<..>
/usr/local/share/perl/5.14.2/Spreadsheet/WriteExcel/Workbook.pm
/usr/local/share/perl/5.14.2/Spreadsheet/WriteExcel/Worksheet.pm
% perldoc -l Spreadsheet::WriteExcel
/usr/local/share/perl/5.14.2/Spreadsheet/WriteExcel.pm
So why? What should I do?
Spreadsheet::ParseExcel and Spreadsheet::WriteExcel are different modules.
Have you installed the former too?
If not, just do the following:
perl -e'use CPAN; install "Spreadsheet::ParseExcel"'
There are 2 ways to go about the same:
use lib '/path/to/directory' where the module is stored
perl -I /path/to/directory test.pl where you include the module using the command line option -I
For more information, please refer to
https://perlmaven.com/how-to-change-inc-to-find-perl-modules-in-non-standard-locations .
Voilá, here you go, happy coding

How to compress a symbolic link?

With tar, I tried to compress a repository in a chroot environment with ssh, but it failed as it just compressed the symbolic link itself.
How can I compress its content?
-bash-3.00$ ls -ail
1263583 lrwxrwxrwx 1 root root 18 Apr 18 2008 mainwebsite_html -> ../../var/www/html
-bash-3.00$ tar -cjvf archive.tar.bz2 mainwebsite_html
-bash-3.00$ ls -ail
7509101 -rw-r--r-- 1 user1 user1 136 Feb 22 08:57 archive.tar.bz2
1263583 lrwxrwxrwx 1 root root 18 Apr 18 2008 mainwebsite_html -> ../../var/www/html
From the tar(1) man page:
-h, --dereference
follow symlinks; archive and dump the files they point to
Take care of placing the "h" option in the correct place. In your example:
tar -cjvf archive.tar.bz2 mainwebsite_html
should be
tar -chjvf archive.tar.bz2 mainwebsite_html

Resources