• Aucun résultat trouvé

Once installed, it can be quite useful to query software. This helps you in a generic way to get more information about software installed on your computer. Moreover, querying RPM packages also helps you fi x specifi c problems with packages, as you will discover in Exercise 4.4.

There are many ways to query software packages. Before fi nding out more about your currently installed software, be aware that there are two ways to perform a query. You can query packages that are currently installed on your system, and it’s also possible to install package fi les that haven’t yet been installed. To query an installed package, you can use one of the rpm -q options discussed next. To get information about a package that hasn’t yet been installed, you need to add the -p option.

To request a list of fi les that are in the samba-common RPM fi le, for example, you can use the rpm -ql samba-common command, if this package is installed. In case it hasn’t yet been installed, you need to use rpm -qpl samba-common-[version-number].rpm, where you also

c04.indd 115

c04.indd 115 1/8/2013 10:43:54 AM1/8/2013 10:43:54 AM

A very common way to query RPM packages is by using rpm -qa. This command generates a list of all RPM packages that are installed on your server and thus provides a useful means for fi nding out whether some software has been installed. For instance, if you want to check whether the media-player package is installed, you can use rpm -qa | grep mediaplayer.

A useful modifi cation to rpm -qa is the -V option, which shows you if a package has been modifi ed from its original version. Using rpm -qVa thus allows you to perform a basic integrity check on the software you have on your server. Every fi le that is shown in the output of this command has been modifi ed since it was originally installed. Note that this command will take a long time to complete. Also note that it’s not the best way, nor the only one, to perform an integrity check on your server. Tripwire offers better and more advanced options. Listing 4.8 displays the output of rpm -qVa.

Listing 4.8: rpm -qVa shows which packages have been modified since installation

[root@hnl ~]# rpm -qVa

The different query options that allow you to obtain information about installed pack-ages, or about packages you are about to install, is also very useful. In particular, the query options in Table 4.2 are useful.

TA B L E 4 . 2 Query options for installed packages

Query command Result

rpm -ql packagename Lists all files in packagename

rpm -qc packagename Lists all configuration files in packagename rpm -qd packagename Lists all documentation files in packagename

c04.indd 116

c04.indd 116 1/8/2013 10:43:54 AM1/8/2013 10:43:54 AM

(Exercise 4.4 provides a nice sample walk-through of how this works.)

A particularly useful query option is the --scripts option. Use rpm -q --scripts packagename to apply this option. This option is useful because it shows the scripts that are executed when a package is installed. Because every RPM package is installed with root privileges, things can terribly go wrong if you install a package that contains a script that wants to do harm. For this reason, it is essential that you install packages only from sources that you really trust. If you need to install a package from an unverifi ed source, use the --script option. Listing 4.9 shows the results of the --script option when applied to the httpd package, which is normally used to install the Apache web server.

Listing 4.9: Querying packages for scripts

[root@hnl Packages]# rpm -q --scripts httpd preinstall scriptlet (using /bin/sh):

# Add the "apache" user

getent group apache >/dev/null || groupadd -g 48 -r apache getent passwd apache >/dev/null || \

/sbin/service httpd condrestart >/dev/null 2>&1 || : [root@hnl Packages]#

As you can see, it requires a bit of knowledge of shell scripting to gauge the value of these scripts. You’ll learn about this later in this book.

Finally, there is one more useful query option: rpm -qf. You can use this option to fi nd out from which fi le a package originated. In Exercise 4.4, you’ll see how this option is used to fi nd out more about a package.

Use repoquery to query packages from the repositories. This command has the same options as rpm -q but is much more efficient for packages that haven’t yet been installed and that are available from the repositories.

c04.indd 117

c04.indd 117 1/8/2013 10:43:54 AM1/8/2013 10:43:54 AM

Download from Wow! eBook <www.wowebook.com>

Finding More Information About Installed Software

In this exercise, you’ll walk through a scenario that often occurs while working with Linux servers. You want to confi gure a service, but you don’t know where to fi nd its confi gura-tion fi les. As an example, you’ll use the /usr/sbin/wpa_supplicant program.

1. Use rpm -qf /usr/sbin/wpa_supplicant to fi nd out from what package the wpa_

supplicant fi le originated. It should show you the wpa_supplicant package.

2. Use rpm -ql wpa_supplicant to show a list of all the fi les in this package. As you can see, the names of numerous fi les are displayed, and this isn’t very useful.

3. Now use rpm -qc wpa_supplicant to show just the confi guration fi les used by this package. This yields a list of three fi les only and gives you an idea of where to start confi guring the service.

Using RPM Queries to Find a Confi guration File

Imagine that you need to confi gure a new service. All you know is the name of the service and nothing else. Based on the name of the service and rpm query options, you can prob-ably fi nd everything you need to know. Let’s imagine that you know the name of the ser-vice is blah. The fi rst step would be to use find / -name blah, which gives an overview of all matching fi lenames. This would normally show a result as /usr/bin/blah. Based on that fi lename, you can now fi nd the RPM it comes from: rpm -qf /usr/bin/blah. Now that you’ve found the name of the RPM, you can query it to fi nd out which confi guration fi les it uses (rpm -qc blah) or which documentation is available (rpm -qd blah). I often use this approach when starting to work with software I’ve never used before.