LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-06-2021, 10:44 AM   #1
wyomoose
LQ Newbie
 
Registered: Apr 2021
Posts: 3

Rep: Reputation: Disabled
rpm -qa --queryformat


We are trying to query the list of installed packages on our linux boxes and send the output to a csv. Part of the requirement is that we have the name of the system on each line. for example
"centserver01 glibc 2.17 Tue May 28 2019"
"Centserver01 pyusb 1.0.0 Tue May 28 2019"
currently we have "rpm -qa --queryformat "%{name} %12{version} %{installtime:date} \n" > softwarefile.csv". Is there any easy way to put the system name directly on every line in the csv? It seems like the only way we can figure it our is to add it to the csv later.
 
Old 04-06-2021, 10:49 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,222

Rep: Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445
do you mean something like this:
Code:
rpm -qa --queryformat "anything %{name} %12{version} %{installtime:date} \n" > softwarefile.csv
?
 
1 members found this post helpful.
Old 04-06-2021, 11:06 AM   #3
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 2,072

Rep: Reputation: Disabled
Your command doesn't produce valid CSV data though. Do you want all the data on each line be in one CSV field or do you want them in separate fields?

If the latter, I'd go with something like:
Code:
rpm -qa --qf $HOSTNAME,'%{n},%{v},"%{installtime:date}"\r\n'
Pay attention to a few things here:
  • %{installtime:date} will be in the current locale unless you prepend something like LC_ALL=C to the command. Just in case, I enclosed it in double quotes because I don't know whether date/time format in your locale includes commas (I hope it doesn't include double quotes though).
  • According to RFC 4180, each line of a CSV file should end in CRLF even if this rule is often violated in Unix/Linux environment.

Last edited by shruggy; 04-06-2021 at 11:20 AM.
 
1 members found this post helpful.
Old 04-06-2021, 11:34 AM   #4
wyomoose
LQ Newbie
 
Registered: Apr 2021
Posts: 3

Original Poster
Rep: Reputation: Disabled
Awesome thanks guys this got us what we need. Appreciate the help.
 
Old 04-06-2021, 12:07 PM   #5
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,222

Rep: Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445
in that case you might want to mark the thread solved.
Also if you wish to say thanks just click on yes.
 
1 members found this post helpful.
Old 04-06-2021, 12:34 PM   #6
wyomoose
LQ Newbie
 
Registered: Apr 2021
Posts: 3

Original Poster
Rep: Reputation: Disabled
So one more question about %{installtime:date} is there any way to format it beside :day :date? The man pages shows how it is formatted and it seems like that is all you get? Tried playing with %{installtime:date strtformat %D} etc it doesn't like anything I have thrown at it. We would like DDMMYYYY. Thanks for your help.
 
Old 04-06-2021, 12:45 PM   #7
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,222

Rep: Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445Reputation: 5445
I think there is no other way. The locale settings (LC_TIME) may influence it.
 
1 members found this post helpful.
Old 04-06-2021, 01:07 PM   #8
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 2,072

Rep: Reputation: Disabled
You can either convert it afterwards or do something like
Code:
#!/bin/sh
rpm -qa --qf '%{n} %{v} %{installtime}\n' |
while read -r name ver itime
do echo $HOSTNAME,$name,$ver,$(date -d@$itime +%d%m%Y)
done
or
Code:
rpm -qa --qf "echo $HOSTNAME,"'%{n},%{v},$(date -d@%{installtime} +%%d%%m%%Y)\n' |
  sh
or even
Code:
rpm -qa --qf "echo $HOSTNAME,"'%{n},%{v},$(date -d@%{installtime} +%%d%%m%%Y)\n' |
  parallel

Last edited by shruggy; 04-06-2021 at 01:47 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] rpm --queryformat VENDOR into an array SigelTown Linux - General 3 03-23-2018 08:28 PM
parsing out from rpm -qa --queryformat into CSV output JCDinPGH Linux - Newbie 4 07-01-2015 08:51 AM
rpm queryformat avijitp Linux - Software 2 04-23-2007 10:47 AM
rpm error only says"rpm: relocation error: rpm: undefined symbol: poptAliasOptions" dlrsims Linux - Newbie 2 11-14-2003 09:22 PM
.src.rpm, .i386.rpm and .i686.rpm hhegab Linux - Software 2 06-19-2003 07:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration