LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 09-19-2011, 09:43 AM   #1
Arighna
LQ Newbie
 
Registered: May 2011
Posts: 16

Rep: Reputation: Disabled
How to find the installed version of a rpm package in a system??


Hi Experts,

I am a newbie in linux. For my project i need to find out the installed version of a rpm package from the rpmdb. This i need to do with C codes. Can anybody throw some light about this to help me out???
 
Old 09-19-2011, 09:47 AM   #2
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
Looks like a good homework exercize - write a C program to check the installed version of an rpm package.
You understand how to find the version with the rpm command right?

There are actually several ways to do this in C. You can consider how the rpms are stored and where the version information lives, then you will realize how to access it ... or you can see how to execute another program from within C and just get it to run rpm.
 
Old 09-19-2011, 10:15 AM   #3
Arighna
LQ Newbie
 
Registered: May 2011
Posts: 16

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Simon Bridge View Post
You understand how to find the version with the rpm command right?
Yes, i know i can check out by the command rpm -qa.

Quote:
Originally Posted by Simon Bridge View Post
There are actually several ways to do this in C. You can consider how the rpms are stored and where the version information lives, then you will realize how to access it ... or you can see how to execute another program from within C and just get it to run rpm.
I don't have sufficient knowledge about handling rpmdb. Maybe if i can find out the list of all the installed packages, and then checking with the desired rpm name (say for e.g. libsecurity) if any installed rpm name matches with it, then that will be the desired output.Please confirm me.
If i am correct in my approach then can you plz tell me how to check from the rpmdb, the list of all the installed package?
 
Old 09-19-2011, 10:50 AM   #4
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2016, Slack14.1 Deb Jessie, + 50+ other Linux OS, for test only.
Posts: 16,276

Rep: Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154Reputation: 3154
List installed packages : rpm -qa | sort > installed-packages.txt
.. Which will save an alphabetic list to the current directory.


rpm -qa --last > last-packages.txt :
Line 1 will show the package with the latest install time.

.
 
Old 09-19-2011, 11:57 AM   #5
samtoddler
Member
 
Registered: Jul 2011
Location: Delhi
Distribution: Cent OS/RHEL
Posts: 37

Rep: Reputation: Disabled
Hi,

You can get your problem solved by stdlib library

Code:
#include<stdlib.h>
system("command_name");
....
or you use the following statement in your c programs
Code:
exec("command > file_output.txt");
but this command can have impact on your program.

samtoddler
 
Old 09-19-2011, 12:05 PM   #6
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
You should have a look at the rpmlib library, it contains all functions you need. Should be a much better way than to launch external programs.
 
1 members found this post helpful.
Old 09-20-2011, 12:44 PM   #7
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
Using the rpm lib should give a more elegant solution, and you can always get hints by examining the source code for the rpm utility. You do know you can get the source right? However, the exact solution you choose should be appropriate to your course ... maybe your teacher wants to see if you can figure out how to execute an external program from within your own? You havn't confirmed this is homework but notice that everyone is replying on that assumption. Without the context, it is hard to pick the proper method for you.
 
Old 09-20-2011, 04:46 PM   #8
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 16,818

Rep: Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408
--- edited ---

Last edited by John VV; 09-20-2011 at 04:49 PM.
 
Old 09-21-2011, 04:31 AM   #9
Arighna
LQ Newbie
 
Registered: May 2011
Posts: 16

Original Poster
Rep: Reputation: Disabled
Hello all,

This is not a school homework. :P Due to some restrictions i can not use rpm binaries in my codes, rather i have to use the rpmlib version 5.6 APIs. So i wud be grateful to you if u can mention here, what are the APIs i can use to find the list of all installed package, which are stored in rpmdb...
 
Old 09-21-2011, 05:23 AM   #10
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 16,818

Rep: Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408
Quote:
For my project i need to find out the installed version of a rpm package from the rpmdb
normally this is done calling rpm to do a database search and list the output
Code:
su -
rpm -qa > ~/RpmList  
or
rpm -qa | sort > ~/RpmList
Quote:
This i need to do with C codes.
then write c wrapper to echo the db search
 
Old 09-21-2011, 10:22 AM   #11
Simon Bridge
LQ Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 198Reputation: 198
You have already been given a link to the rpmlib functions and specification - that is all the api anyone usually needs. What? You want us to write the actual code for you? We have already provided example code. Perhaps I should send you a schedule of my fees?

I don't understand what restrictions, other than homework, would prevent you from calling the rpm binary from within a C wrapper. As observed, this would be the usual way and it is one of the things it is designed for. Without the specifics of what you are doing, nobody can produce code any better suited to you than the examples already given to you.

(Note: linux does not, iirc, have a formal api - it does not need one: you have the entire source code.)
 
  


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] Package requires earlier version of an installed package Doug Hutcheson Linux - Software 3 12-30-2010 10:55 PM
Find Installed Location of RPM Package in Unix suman5u Linux - Newbie 2 03-26-2010 05:28 AM
RPM package manager says package needs to be installed. But I already installed it! nick623 Linux - Software 2 05-24-2005 03:15 AM
How to know the version of a package installed ? rockwell_001 Linux - Newbie 1 04-12-2005 04:25 PM
is the a package of ndiswrapper-1.1 version in rpm golpemortal Linux - Wireless Networking 2 03-28-2005 10:04 PM


All times are GMT -5. The time now is 06:31 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration