LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   script for software inventory (https://www.linuxquestions.org/questions/linux-software-2/script-for-software-inventory-4175533566/)

jaykbvt 02-10-2015 02:48 AM

script for software inventory
 
Hi Guys,

I'm trying to write a script which can give me a list of installed packages in csv format.

In windows I can query registry keys or ask wmi for installed products.

I'm using CentOS so I thought of usning

yum info installed

its gr8 gives all the info but it gives info in its own format...like given below..

=======================

Name : ConsoleKit
Arch : x86_64
Version : 0.4.1
Release : 3.el6
Size : 263 k
Repo : installed
From repo : anaconda-CentOS-201311272149.x86_64
Summary : System daemon for tracking users, sessions and seats
URL : http://www.freedesktop.org/wiki/Software/ConsoleKit
License : GPLv2+
Description : ConsoleKit is a system daemon for tracking what users are logged
: into the system and how they interact with the computer (e.g.
: which keyboard and mouse they use).
:
: It provides asynchronous notification via the system message bus.


=======================

Is there any way possible to get only Name, Version, Release, Size, Repo, Summary, URL,Licence in a csv file...???

Probably with combination of awk, sed, grep...??

Or should I use any other approach to get software inventory...??


--
Thanks & Regards,
jaykbvt

rtmistler 02-10-2015 12:29 PM

The way I would do it would be via script and using any of the utilities which you've mentioned.

Basically for a script, you can do anything in the script which you can do in the command line, so if you run that command and use awk, sed, and/or grep to process the output, you can use those same commands in a script. A brute force tactic would be to get the output of the command into one large sting or array of strings and then process that entity repeatedly to grab each desired attribute which you'd save into disparate variables. Then at the end of the parsing, you can output that into another file via the echo command and use comma separations. Once you get it right for one package report, you can then structure it to be a loop and make a set of arrays and then print them all out after the parse phase is complete. Or you could just not bother with arrays and just add one line to the output file each time you process a new package. I like that second option better because if for some reason the package report command locks up, you at least get some output.

There are links for BASH programming in my signature. I also have a blog entry with some suggestions how to code and debug BASH scripts.

If you get some interim results but get stuck, post your efforts and people will likely offer suggestions for improvements or solutions.

jaykbvt 02-11-2015 01:30 AM

Hi,

Thanks for reply..

Is there any management interface in linux,like WMI in Windows, which can be scripted..?




--
Thanks & Regards,
jaykbvt

chrism01 02-11-2015 04:39 AM

No idea what WMI is ;) but if you run
Code:

rpm --querytags
I think you'll be pleasantly surprised

Here's an example of how to use it
Code:

rpm -qa 'kernel*' --queryformat "%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n"

jaykbvt 02-11-2015 05:39 AM

Oh gr8 man....!!!

Thats what I was looking for...!!

It matches my requirement perfectly..:D

Just a query...does rpm cover all the software packages installed...?? Or is there any other way also to install which can't be reported through this command..??

like there a huge difference between number of packages reported by both command.

==================================
[root@srv1 ~]# yum list installed |wc
1672 3526 113464
[root@srv1 ~]# rpm -qa | wc
1175 1175 39819
[root@srv1 ~]#

==================================


--
Thanks & Regards,
jaykbvt


All times are GMT -5. The time now is 10:51 AM.