All rpm packages can run scripts after a package is added or removed. How do I view pre/post install and uninstall rpm file scripts under rpm based Linux distributions?
The option --scripts to rpm command displays the package specific scriptlet(s) that are used as part of the installation and uninstallation processes. Use the following command line option to view rpm file scripts for .rpm file:
rpm -qp --scripts filename.rpm
For example, to list all scripts for memcached-1.2.8-1.el5.x86_64.rpm, enter:
$ rpm -qp --scripts memcached-1.2.8-1.el5.x86_64.rpm
Sample outputs:
preinstall scriptlet (using /bin/sh):
getent group memcached >/dev/null || groupadd -r memcached
getent passwd memcached >/dev/null || \
useradd -r -g memcached -d /var/run/memcached \
-s /sbin/nologin -c "Memcached daemon" memcached
exit 0
postinstall scriptlet (using /bin/sh):
/sbin/chkconfig --add memcached
preuninstall scriptlet (using /bin/sh):
if [ "$1" = 0 ] ; then
/sbin/service memcached stop > /dev/null 2>&1
/sbin/chkconfig --del memcached
fi
exit 0
postuninstall scriptlet (using /bin/sh):
if [ "$1" -ge 1 ]; then
/sbin/service memcached condrestart > /dev/null 2>&1
fi
exit 0To view scripts for installed packages, enter:
# rpm -q --scripts packageName
# rpm -q --scripts httpd
Sample outputs:
preinstall scriptlet (using /bin/sh):
getent group memcached >/dev/null || groupadd -r memcached
getent passwd memcached >/dev/null || \
useradd -r -g memcached -d /var/run/memcached \
-s /sbin/nologin -c "Memcached daemon" memcached
exit 0
postinstall scriptlet (using /bin/sh):
/sbin/chkconfig --add memcached
preuninstall scriptlet (using /bin/sh):
if [ "$1" = 0 ] ; then
/sbin/service memcached stop > /dev/null 2>&1
/sbin/chkconfig --del memcached
fi
exit 0
postuninstall scriptlet (using /bin/sh):
if [ "$1" -ge 1 ]; then
/sbin/service memcached condrestart > /dev/null 2>&1
fi
exit 0
[root@txvip1 tmp]# rpm -q --scripts httpd
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
fi
See also:
man rpm
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop














{ 0 comments… add one now }