Cleaning the yum cache – yum clean options

YUM - Yellowdog Updater Modifier

yum is an interactive, rpm based, package manager. It performs system updates, installation of new packages, removal of old packages, queries on the installed and/or available packages, and more.

Note the first bit below, yum clean all only cleans files for currently enabled repos. To really clean all you need to use

yum clean all --enablerepo='*'

From the yum man page:


The following are the ways which you can invoke yum in clean mode. Note that “all files” in the commands below means “all
files in currently enabled repositories”. If you want to also clean any (temporarily) disabled repositories you need to
use –enablerepo=’*’ option.

yum clean expire-cache

Eliminate the local data saying when the metadata and mirrorlists were downloaded for each repo. This means yum will revalidate the cache for each repo. next time it is used. However if the cache is still valid, nothing significant was deleted.

yum clean packages

Eliminate any cached packages from the system. Note that packages are not automatically deleted after they are

yum clean headers

Eliminate all of the header files, which old versions of yum used for dependency resolution.

yum clean metadata

Eliminate all of the files which yum uses to determine the remote availability of packages. Using this option will
force yum to download all the metadata the next time it is run.

yum clean dbcache

Eliminate the sqlite cache used for faster access to metadata. Using this option will force yum to download the
sqlite metadata the next time it is run, or recreate the sqlite metadata if using an older repo.

yum clean rpmdb

Eliminate any cached data from the local rpmdb.

yum clean plugins

Tell any enabled plugins to eliminate their cached data.

yum clean all

Does all of the above.


Run Netflix on Ubuntu in seconds

Since Microsoft Silverlight isn’t available on Linux, so Netlix hasn’t been either. Now there’s an unofficial desktop package available. You simply add the repository, run updates, and download and install the ‘netflix-desktop’ package. The package bundles WINE and Netflix, and makes the process really easy.


Three simple commands

Three simple commands in the terminal window:
sudo apt-add-repository ppa:ehoover/compholio
sudo apt-get update
sudo apt-get install netflix-desktop

Then search for ‘Netlix’ and launch the application.

Netflix Shortcut

Netflix on Ubuntu

It launches in full screen mode, but you can press F11 to exit full screen mode. Close the application by clicking on the close button in the upper right of the screen, or press Alt + F4. To go back to the Netflix menu, click the left arrow at the top left of the screen.


MSSQL Query from Linux- FreeTDS for Nagios Monitoring

FreeTDS for MSSQL queries from Linux

Using FreeTDS

Need to monitor a MSSQL server instance from Nagios? You can use FreeTDS to execute a MSSQL query from a Linux box.

Here’s how:

  1. Install FreeTDS:
    yum install freetds
  2. Configure FreeTDS (vi /usr/local/etc/freetds.conf):

    host =
    port = 1433
    tds version = 8.0
  3. Configure ODBC driver for FreeTDS (/etc/odbcinst.ini):

    # Define where to find the driver for the Free TDS connections.
    Description = MS SQL database access with Free TDS
    Driver = /usr/lib/
    Setup = /usr/lib/
    UsageCount = 1
  4. Test connectivity:

    [root@techpain]# tsql -H servername -p 1433 -U dbuser -P dbpass
    locale is "en_US.UTF-8"
    locale charset is "UTF-8"
    using default charset "UTF-8"
    1> select field11 from column1 where field1 like '10%'
    2> GO
    (7 rows affected)
    1> quit

Nagios MSSQL query

FreeTDS is cool because it allows you to use Nagios to query a MSSQL server using check_mssql command. Here’s how:

Download the check_mssql plugin to the plugins dir on your Nagios server. You can find it at the Nagios Exchange site.

Create command, host, and service definitions for it:

define command {
command_name check_mssql
command_line $USER1$/check_mssql -H hostname -U dbuser -P dbpass -q "select count(*) from column1 where field1 like '10%';" -r "7" -w 8 -c 10

define host {
host_name ServerName
alias MSSQL server
check_command check-host-alive
notification_interval 15
notification_options d,u,r
max_check_attempts 3
active_checks_enabled 1
passive_checks_enabled 0
notifications_enabled 1
check_period 24x7
notification_period 24x7
contact_groups admins

define service {
use generic-service
host_name ServerName
service_description MSSQLquery
check_command check_mssql

In the above example, Nagios executes the query expects a return of 7, warns at 8, and goes crit at 10.


Find Dell service tag from within the OS – Linux and Windows

Get your Dell service tag (sometimes referred to as a serial number) from inside your operating system. Here are the Windows and Linux commands you’ll need.

Windows command

wmic bios get serialnumber
wmic bios get serialnumber -

Linux command

dmidecode -s system-serial-number  or lshw

Details on these and other similar commands can be found at

Additional Notes

These commands pull the serial number from the BIOS. A SuperMicro server of mine shows serial number 1234567890 while a VM running in VirtualBox shows 0. If you receive unexpected output, try running the commands without the extra options to get more information, for example: dmidecode | less or wmic bios


Monitoring Temperature and Fans with lm_sensors

How to install and configure lm_sensors for temp and fan monitoring

Install the lm_sensors package

sudo yum install lm_sensors or sudo apt install lm-sensors

Configure lm_sensors

Enter ‘YES’ for all prompts
Check what module: cat /etc/sysconfig/lm_sensors
Load the module: modprobe (module name)

Check temperature and fan data

(in Fahrenheit): sensors -f

lm_sensors -

lm_sensors Manual Page

Usage: sensors [OPTION]... [CHIP]...
-c, --config-file     Specify a config file (default: /etc/sensors.conf)
-h, --help            Display this help text
-s, --set             Execute `set' statements (root only)
-f, --fahrenheit      Show temperatures in degrees fahrenheit
-A, --no-adapter      Do not show adapter for each chip
-U, --no-unknown      Do not show unknown chips
-u, --unknown         Treat chips as unknown ones (testing only)
-v, --version         Display the program version Use `-' after `-c' to read the config file from stdin.
If no chips are specified, all chip info will be printed.
Example chip names:
lm78-i2c-0-2d   *-i2c-0-2d
lm78-i2c-0-*    *-i2c-0-*
lm78-i2c-*-2d   *-i2c-*-2d
lm78-i2c-*-*    *-i2c-*-*
lm78-isa-0290   *-isa-0290
lm78-isa-*      *-isa-*

Configure monitoring

Write a script to cron or check via Nagios/nrpe. This can be as simple or complex as you like. I like to use something like this since it checks each temp individually, and has a separate threshold for each in a single script:


# By techpain 2012-12-11
# Check temperatures

TEMP1=$(sensors -f | grep -A3 'k8temp-pci-00c3' | grep Core0 | awk '{print $3}' | sed 's/\+//' | sed 's/.\{4\}$//')
TEMP2=$(sensors -f | grep -A3 'k8temp-pci-00c3' | grep Core1 | awk '{print $3}' | sed 's/\+//' | sed 's/.\{4\}$//')
TEMP3=$(sensors -f | grep -A3 'k8temp-pci-00cb' | grep Core0 | awk '{print $3}' | sed 's/\+//' | sed 's/.\{4\}$//')
TEMP4=$(sensors -f | grep -A3 'k8temp-pci-00cb' | grep Core1 | awk '{print $3}' | sed 's/\+//' | sed 's/.\{4\}$//')

if [ $TEMP1 -le 85 ] && [ $TEMP2 -le 75 ] && [ $TEMP3 -le 100 ] && [ $TEMP4 -le 100 ]
echo "OK - $TEMP1,$TEMP2,$TEMP3,$TEMP4 - cool as the other side of the pillow"
exit 0
logger "WARN - $TEMP1,$TEMP2,$TEMP3,$TEMP4 - it's getting hot in here"
echo "WARN - $TEMP1,$TEMP2,$TEMP3,$TEMP4 - it's getting hot in here"
exit 1

lm_sensors monitoring script output -


Timestamp your bash history – Modify .bashrc

Need a date and/or time stamp in your bash history? Simply set the HISTTIMEFORMAT in your (or other users) .bashrc file:


Now the ‘history’ command shows your timestamp next to the command issued:

[root@hostname ~]# history | tail -n4
998 05/21/12 11:25:41 vi .bashrc
999 05/21/12 11:25:41 exit
1000 05/21/12 11:25:43 ls
1001 05/21/12 11:25:46 history | tail -n5

history timestamp -


df error – ‘df: cannot read table of mounted file systems’

[root@host]# df -h
df: cannot read table of mounted file systems
[root@host]# cat etc/mtab
[root@host]# lvdisplay
Parse error at byte 6 (line 1): unexpected token

This is often related to a disk space issue. A post from recommended freeing up space and then rebuilding /etc/mtab from /proc/mounts like so:
[root@host]# grep -v rootfs /proc/mounts > /etc/mtab
Seemed to do the trick, df is now returning expected results.

df -


Bash Scripting repetitive tasks – while read x; do

Use a “while loop” type bash script for repetitive Linux tasks

More “while loop” bash scripting examples at

An audit on a Linux server made it necessary to get information regarding every user on the machine, and match those users to a mail directory (which may or may not have a different name). Instead of running the ‘finger’ command three hundred times and copying the output somewhere I used this:
#! /bin/sh
while read username; do
finger ${username}
done < inputfile > outputfile
exit 0

I saved this as and copied each of the usernames to the file ‘inputfile’. The ‘inputfile’ contained just the usernames that I cut and pasted from the mail directory in question, and looked like this:
bill frank keith user01 user05 user09
carl gary larry user02 user06 user10
dan heather mary user03 user07 user11
denise joe nancy user04 user08 user12

Running ran the finger command on each user in the ‘inputfile’ and immediately output a list of users that did not exist. It also created ‘outputfile’, which contained a list of the information on each user:
Login: bill Name: Bill Person
Directory: /home/b/bill Shell: /bin/nologon
Never logged in.
No mail.
No Plan.
Login: carl Name: Carl Guy
Directory: /users/carl Shell: /bin/nologon
Never logged in.
No mail.
No Plan.
Login: dan Name: Dan Theman
Directory: /users/dan Shell: /bin/nologon
Never logged in.
No mail.
No Plan.


Fail2Ban – Reload banned IP’s after a restart

Restart fail2ban and load the previously banned IPs back into iptables


Restarting fail2ban will drop all of your currently banned IP’s from iptables. To reload those banned IP’s try this.

First, output your currently fail2-banned IP’s to a text file with the iptables commands:
iptables-save | grep '-A fail2ban' | sed 's/-A/iptables -A/' > bannedIPs.txt

Stop fail2ban, make your config changes, etc. and restart:
service fail2ban stop
service fail2ban start

Load your iptables commands by piping your saved rules to bash:
cat bannedIPs.txt | /bin/bash


Broken yum – yum hangs when trying to remove a package

I removed a package with yum “successfully” but was unable to reinstall it, as yum seemed to think it was already installed.

YUM Commands

To check a package for corruption:
rpm -Vv package

To remove a package from the rpm database:
rpm -e --justdb --nodeps package

Additional notes

Also, it’s probably a good idea to yum clean all if you didn’t already, and maybe check out all of the yum clean options.

YUM - Yellowdog Updater Modifier