LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 08: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, 08: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, 09: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, 09:50 AM   #4
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen DK
Distribution: PCLinuxOS2023 Fedora38 + 50+ other Linux OS, for test only.
Posts: 17,511

Rep: Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641Reputation: 3641
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, 10: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, 11:05 AM   #6
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
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, 11:44 AM   #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, 03:46 PM   #8
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
--- edited ---

Last edited by John VV; 09-20-2011 at 03:49 PM.
 
Old 09-21-2011, 03: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, 04:23 AM   #10
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
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, 09: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



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

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

All times are GMT -5. The time now is 05:25 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
Open Source Consulting | Domain Registration