View Installation / Uninstallation Script Inside The RPM File

Q. How do I view the pre / post installation or uninstallation script inside the RPM file called foo.rpm under Red Hat Enterprise Linux / RHEL / CentOS / Fedora / Suse Linux? How do I list the package specific scriptlet(s) that are used as part of the installation and uninstallation processes?

A. To list the package specific scriptlet(s) that are used as part of the installation and uninstallation processes pass –scripts option to rpm command. You also need to specify the following options:

-q option : Query option
-p option : Query an (uninstalled) package PACKAGE_FILE. The PACKAGE_FILE may be specified as an ftp or http style URL, in which case the package header will be downloaded and querie).

General syntax for uninstalled foo.rpm file

$ rpm -qp --scripts foo.rpm
Find out Installation / Uninstallation scripts inside the rpm file called monit-4.9-2.el5.rf.x86_64.rpm:
$ rpm -qp --scripts monit-4.9-2.el5.rf.x86_64.rpm
Sample output:

warning: monit-4.9-2.el5.rf.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 6b8d79e6
preinstall scriptlet (using /bin/sh):
if ! /usr/bin/id monit &>/dev/null; then
        /usr/sbin/useradd -M -r -d /var/lib/monit -s /bin/sh -c "monit daemon" monit || \
                logger -t monit/rpm "Unexpected error adding user \"monit\". Aborting installation."
postinstall scriptlet (using /bin/sh):
/sbin/chkconfig --add monit
preuninstall scriptlet (using /bin/sh):
if [ $1 -eq 0 ]; then
        service monit stop &>/dev/null || :
        /sbin/chkconfig --del monit
postuninstall scriptlet (using /bin/sh):
/sbin/service monit condrestart &>/dev/null || :
if [ $1 -eq 0 ]; then
        /usr/sbin/userdel monit || logger -t monit/rpm "User \"monit\" could not be deleted."

General syntax for installed httpd package

$ rpm -q --scripts httpd
Sample output:

preinstall scriptlet (using /bin/sh):
# Add the "apache" user
/usr/sbin/useradd -c "Apache" -u 48 \
        -s /sbin/nologin -r -d /var/www apache 2> /dev/null || :
postinstall scriptlet (using /bin/sh):
# Register the httpd service
/sbin/chkconfig --add httpd
preuninstall scriptlet (using /bin/sh):
if [ $1 = 0 ]; then
        /sbin/service httpd stop > /dev/null 2>&1
        /sbin/chkconfig --del httpd

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 2 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
2 comments… add one
  • Vinay Aug 23, 2008 @ 8:49

    To see what is there in a rpm type the following command:

    rpm2cpio foo.rpm | cpio -idmv

  • ArtUrlWWW Nov 20, 2013 @ 12:26

    Thank you very much!.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum