Me in IT UNIX/Linux Consultancy is based in Utrecht, The Netherlands and specialized in UNIX and Linux consultancy. Experience with Red Hat Enterprise Linux (Red Hat Certified Architect), Fedora Project, CentOS, OpenBSD and related released Open Source products makes Me in IT UNIX/Linux Consultancy a great partner in implementing, maintaining and upgrading your environment.

Open Source software is an important aspect of any Linux distribution. Me in IT UNIX/Linux Consultancy tries to use Open Source software where possible and tries to share experiences actively. In the articles section you will find many UNIX/Linux adventures shared for others to benefit.

Add a permanent static route to Mac OS X

As a reminder for myself, but likely useful for you! If you are in a situation where you'd like to add a static route to you Mac OS X machine, you could issue:

$ sudo route add 10.0.0.0/8 192.168.1.1

This commands tells the TCP/IP stack to sent traffic with the destination 10.*.*.* via 192.168.1.1. But, this command is only active after issuing it and before the next reboot. To "save" this command, make it permanent, you can take these simple steps.
$ sudo mkdir /Library/StartupItems/AddRoute
# cd /Library/StartupItems/AddRoute
$ echo "{
        Description     = \"Add static routing tables\";
        Provides        = (\"AddRoutes\");
        Requires        = (\"Network\");
        OrderPreference = \"None\";
}" > StartupParameters.plist
$ echo "#!/bin/sh

# Set up static routing tables
# Roark Holz, Thursday, April 6, 2006

. /etc/rc.common

StartService ()
{
        ConsoleMessage "Adding Static Routing Tables"
sudo route add 10.0.0.0/8 192.168.200.15
}

StopService ()
{
        return 0
}

RestartService ()
{
        return 0
}

RunService "$1"" > AddRoutes
$ sudo chmod 755 AddRoutes

Now you should be prepared. After a reboot, the route will be visible. (netstat -rnf inet)

Nagios check for Centreon to create CPU graphs for Linux

Centreon is a great front-end for Nagios, the well known monitoring tool.

Nagios only performs "up" and "down" checks, Centreon adds performance graph capabilities.

Centreon comes with many checks to measure values, like traffic on eth0, a ping response time check, an ntp check and so on. Many checks are based on SNMP, so for Linux machines net-snmp should be installed.

What Centreon is missing, is an SNMP check that reports CPU usage and graphs the information. Here is a shell script to get the values for a specified host and return the CPU-idle percentage, CPU-system percentage and CPU-user percentage.

The script depends on a binary snmpget found in the package net-snmp-utils. Install it on the Nagios pollers that perform this check.

This script implements Performance Data as described by Nagios, which is very short means that besides outputting readable data, it also outputs performance data after the pipe ("|") mark, separated by a comma.
The script has been designed to incorporate all described requirements by Nagios plugins.

#!/bin/sh

# Nagios plugin to report CPU usage on Linux boxes.

usage() {
# This function is called when a user enters impossible values.
echo "Usage: $0 -H HOSTADDRESS [-C COMMUNITY] [-w WARNING] [-c CRITICAL] [-v VERSION]"
echo
echo " -H HOSTADDRESS"
echo "     The host to check, either IP address or a resolvable hostname."
echo " -w WARNING"
echo "     The percentage of cpu-idle to start warning, defaults to 15."
echo " -c CRITICAL"
echo "     The percentage op cpu-idle to reflect a critical state, defaults to 5."
echo " -C COMMUNITY"
echo "     The SNMP community to use, defaults to public."
echo " -v VERSION"
echo "     The SNMTP version to use, defaults to 2c."
exit 3
}

readargs() {
# This function reads what options and arguments were given on the
# command line.
while [ "$#" -gt 0 ] ; do
  case "$1" in
   -H)
    if [ "$2" ] ; then
     host="$2"
     shift ; shift
    else
     echo "Missing a value for $1."
     echo
     shift
     usage
    fi
   ;;
   -w)
    if [ "$2" ] ; then
     warning="$2"
     shift ; shift
    else
     echo "Missing a value for $1."
     echo
     shift
     usage
    fi
   ;;
   -c)
    if [ "$2" ] ; then
     critical="$2"
     shift ; shift
    else
     echo "Missing a value for $1."
     echo
     shift
     usage
    fi
   ;;
   -C)
    if [ "$2" ] ; then
     community="$2"
     shift ; shift
    else
     echo "Missing a value for $1."
     echo
     shift
     usage
    fi
   ;;
   -v)
    if [ "$2" ] ; then
     version="$2"
     shift ; shift
    else
     echo "Missing a value for $1."
     echo
     shift
     usage
    fi
   ;;
   *)
    echo "Unknown option $1."
    echo
    shift
    usage
   ;;
  esac
done
}

setvariables() {
# Here is a function to set some default values.
cpurawidle="UCD-SNMP-MIB::ssCpuRawIdle.0"
cpurawuser="UCD-SNMP-MIB::ssCpuRawUser.0"
cpurawsystem="UCD-SNMP-MIB::ssCpuRawSystem.0"
if [ ! "$warning" ] ; then warning="15" ; fi
if [ ! "$critical" ] ; then critical="5" ; fi
tmpdir="/tmp/nagios"
}

checkvariables() {
# This function checks if all collected input is correct.
if [ ! "$host" ] ; then
  echo "Please specify a hostname or IP address."
  echo
  usage
fi
if [ "$warning" -lt "$critical" ] ; then
  echo "Critical may not be higher than warning. Please modify your critical an warning values."
  echo
  usage
fi
if [ ! "$community" ] ; then
  # The public community is used when a user did not enter a community.
  community="public"
fi
if [ ! "$version" ] ; then
  # Version 2c is used when a user did not enter a version.
  version="2c"
fi
if [ ! -d "$tmpdir" ] ; then
  mkdir "$tmpdir"
  if [ $? -gt 0 ] ; then
   echo "Unknown cannot create $tmpdir!"
   exit 3
  fi
fi
}

getandprintresults() {
# First, get all values in one snmpget session. I think this is lighter for
# the machine that is queried compared to three separated snmpgets.
snmpget -c "$community" -v "$version" -t 3 "$host" "$cpurawidle" "$cpurawuser" "$cpurawsystem" | while read mib equals type digit ; do
case "$mib" in
  # This output is returned for the cpuidle value.
  UCD-SNMP-MIB::ssCpuRawIdle.0)
   cpuidlevalue="$digit"
  ;;
  # This output is returned for the cpuuser value.
  UCD-SNMP-MIB::ssCpuRawUser.0)
   cpuuservalue="$digit"
  ;;
  # This output is returned for the cpusystem value.
  UCD-SNMP-MIB::ssCpuRawSystem.0)
   cpusystemvalue="$digit"

   if [ -f "$tmpdir"/"$host".cpuidle ] ; then
    cpuidlediff=$(($cpuidlevalue - $(cat "$tmpdir"/"$host".cpuidle)))
   fi
   echo "$cpuidlevalue" > "$tmpdir"/"$host".cpuidle

   if [ -f "$tmpdir"/"$host".cpuuser ] ; then
    cpuuserdiff=$(($cpuuservalue - $(cat "$tmpdir"/"$host".cpuuser)))
   fi
   echo "$cpuuservalue" > "$tmpdir"/"$host".cpuuser

   if [ ! -f "$tmpdir"/"$host".cpusystem ] ; then
    echo "$cpusystemvalue" > "$tmpdir"/"$host".cpusystem
    echo "First run, gathering data."
    exit 3
   else
    cpusystemdiff=$(($cpusystemvalue - $(cat "$tmpdir"/"$host".cpusystem)))
    echo "$cpusystemvalue" > "$tmpdir"/"$host".cpusystem
   fi

   # Add all differences, so a calculation of the percentage can be made later.
   allcpu=$(($cpuidlediff + $cpuuserdiff + $cpusystemdiff))

   # Now calculate how many percent each value represents.
   cpuidlevalue=$((($cpuidlediff*100)/$allcpu))
   cpuuservalue=$((($cpuuserdiff*100)/$allcpu))
   cpusystemvalue=$((($cpusystemdiff*100)/$allcpu))

   # Now see if any of these percentages is over a threshold.
   if [ "$cpuidlevalue" -lt "$critical" ] ; then
    # First see if it's in a critical state.
    echo "CPU CRITICAL idle value: $cpuidlevalue%|cpuidle=$cpuidlevalue% cpuuservalue=$cpuuservalue% cpusystemvalue=$cpusystemvalue%"
    exit 2
   elif [ "$cpuidlevalue" -lt "$warning" ] ; then
    # Now see if warning applies.
    echo "CPU WARNING idle value: $cpuidlevalue%|cpuidle=$cpuidlevalue% cpuuservalue=$cpuuservalue% cpusystemvalue=$cpusystemvalue%"
    exit 1
   else
    # If neither critical, nor warning apply, it must be OK!
    echo "CPU OK idle value: $cpuidlevalue%|cpuidle=$cpuidlevalue% cpuuservalue=$cpuuservalue% cpusystemvalue=$cpusystemvalue%"
    exit 0
   fi
  ;;
  esac
done
}

# The calls to the different functions.
readargs "$@"
setvariables
checkvariables
getandprintresults

Don't forget to chmod (755) the script on the Poller(s).

Now go into the Centreon web front end and add a command at:
Configuration - Commands - Add.
I named the check "check_cpu" where the command line is:

$USER1$/check_snmp_cpu -H $HOSTADDRESS$ -C $ARG1$

Bind this check to a service template and bind a hostgroup to the service template. Remember Centreon does not use $USER2$, but $_HOSTSNMPCOMMUNITY$.

Pasting shell scripts from Microsoft Word into Putty

As a Linux/UNIX engineer you will have to cope with the strange behaviour of Microsofts products. Microsoft Word replaces a simple double quote (") for an angled quote. Now when you paste that code into Putty, your (angled) quotes are replaced for dots.

To correct this behaviour open Microsoft Word, click Tools then Autocorrection options and on the unselect Smart Quotes. (You may want to disable other "handy" features as well.

Finally, I am able to paste documented code into Putty!

Simple AWK script to show filesystems that are almost full

Here is a simple oneliner to show filesystems that are nearly full:

df -k | awk '$4 > 85 {print $7,$4}'

What it does;

  1. df -k - This displays the filesystems and how full they are.
  2. awk '$4 > 85 {print $7,$4}' - This prints the 7th and 4th column, when the 4th column is greater than 85.

An alternative to top for AIX

Almost everybody loves the GNU command top. Top displays information about what's going on at your system. Some systems don't provide top, this script can be used as an alternative for top:

#!/bin/sh

# If the shell script is stopped with CTRL+C, the screen
# might need to be sized correctly.
trap 'eval $(resize); exit 2' 2

# A loop to display activity.
while [ 1 ] ; do
eval $(resize)
output=$(ps -eF "pcpu time pid user comm" | grep -v TIME | sort -rn | head -$(("$LINES"-2)))
echo ' %CPU      TIME    PID     USER    COMMAND'
echo "$output"
sleep 3
done

Running an Open Source Phone Part 1

Introduction - Why do we need an Free Software phone?

As we all know, when purchasing a new phone, it often has a slew of restrictions. On the telephony side, you are usually only allowed to use an authorised type of SIM card in the phone but there are far greater restrictions as to what you can do with the software on the phone. Almost all phones out there use proprietary software and, in the cases where a Free Software kernel is used, it is always hidden away and you can't modify your phone by installing a free GNU/Linux distribution on it since only authorised, signed operating systems will be booted.

Besides the software in the phone not being Free (as in freedom) software, there are often arbitrary restrictions on how you can use the phone. For example, DRM to restrict how you can play the music you have legally purchased, you cannot install you own applications but only applications approved by the Telco and/or phone vendor - think of the iPhone.

I am writing a series of articles in order to share my experiences and hopefully help people get familiar with Free Software on mobile devices, specifically cellular telephones. This first article will focus on a high level introduction to some of the hardware and software available for open source/free software phones. For those interested - I am using a Neo Freerunner running QTextended as my daily phone.

The Hardware

All this Free Software is no good if there is no phone you can install it on so I will now give a non-exhaustive list of the mobile devices I know about on which you can install free software.

The Neo Freerunner

The Neo Freerunner is designed to be an open phone from the ground up - the manufacturing diagrams are published as CAD files which anyone can use as a basis for another phone. The Neo Freerunner is the most promising, truly open phone that I am aware of and has a highly active community developing software for the Neo Freerunner and future phones from Openmoko.

The software on this phone (covered in Part 2) is not quite ready for end-user use but can be used as a daily phone by enthusiasts. That said, I expect that basic functionality will be stable in half a year.

Google G1

The Google G1 is a Linux based phone brought out by Google, it seems they want to compete with the Apple iPhone. The retail G1 is a locked phone that will only run authorised images so no change there. However, you can gain access to the full functionality of your phone in two ways; rooting the phone or buying the developer G1 called the "Android Dev Phone 1". Once this has been done you can proceed to experiment to your hearts content with the underlying Linux system making up the G1 - with some limitations.

The Trolltech Greenphone

The now discontinued Green phone used a software stack called Qtopia created by Trolltech (now owned by Nokia) - the same people who develop the QT toolkit in use by such projects as KDE and countless other, smaller applications.

The idea behind the Greenphone was to promote Qtopia as a mobile development platform and not as an end-user telephone. Trolltech no longer ships the Greenphone and the Qtopia software stack as been renamed to QTextended. QTextended has just released version 4.4.3, which will be the last release of the QTextended platform as this too is being discontinued but a community maintained version will still be available and may even become better than the Trolltech version.

Nokia Internet Tablet

The Nokia N810 supports the running of Open Source software - the main software stack target at this device is the Maemo plaform but it also supports QTextended and Debian GNU/Linux. By installing Debian on the N810 you can access to the vast software repositories available to Debian systems.

iPhone

Yes, you read correctly, you can now run Linux on your iPhone. This project is still in its very early stages and already seems to be laying the groundwork quite well. Definitely worth keeping an eye on. Also, I suspect you will need a jail-broken phone in order to install Linux on your iPhone and Apple may release updates to their boot loader ROM that will make it difficult to install Linux on the iPhone.
Netbooks

And, let's not forget, the ever popular Netbooks being made by seemingly all major computer manufacturers. While not strictly speaking a phone or a "tablet", they are nevertheless very mobile and so I will cover them here. The recent Netbook trend all started with the Asus Eee PC which made people realise that they just need "good enough" computing rather than a super computer on their lap.

One can easily install any Linux distribution on these devices and, when combined with a mobile broadband device (aka "dongle"), you have a powerful, mobile Internet device. Especially useful for those of us that are on call!

A very good history of the Netbook can be found at Arstechnica.

Next Article

In the next article I will be taking a deeper look at the various Free Software stacks that are available for running on your mobile device. Stay tuned!

Hopeful: Linux professionals will survive the recession

Linux professionals (administrators, engineers, architects) will manage during the financial crisis. That's what sites like Cyberciti predict.

It's hard to tell what the impacts of the recession will be for Linux professionals, but here is why "we" should be perfectly fine:

  • Linux is free - Sure it is, although the "enterprise programs" all cost money when you require support. Be aware that free (as in money) software does not mean installing and maintaining it is free; you need Linux professionals to help out.
  • Linux is scalable - You can start now for a limited amount of money, when better times arrive, you will be ready to expand your infrastructure.
  • Linux is stable - Invest some money now to setup infrastructure, when it's done it won't just stop working!
  • Linux is the way to go - For the server market Linux is very common. This will only grow in the years to come so you will be ready for the future.

Well Linux professional, hope that helps you to manage during these "interesting" times.

Aesthetics of shell scripting

Here is the problem; you need to print a single line filled with dashes. Will you just echo 80 dashes or write a beautiful loop for it?

The ease solution

$ echo "--------------------------------------------------------------------------------"

The aesthetic solution

$ n=0 ; while [ $n -lt 80 ] ; do printf "-" ; n=$(($n+1)) ; done ; echo

Both give the same result, but the easy solution is faster. Result from the machine where I am working on:

Test Easy way Aesthetics way
Time to execute: 0.000 seconds 0.039 seconds
Bytes on disk 88 70
Complexity level 1 7
System calls 37 657
lines printed in 1 minute 1471371 18318

The numbers show that simplicity is more efficient.

Prepare your Linux box for Daylight Saving Time (summer or winter time)

The summertime is starting soon. What can you do on your Linux machine to be prepared for Daylight Saving Time?

The bad news

Time is a very complicated matter; it shifts every half year, there are leap years and seconds, some countries change the start or end date of summertime, many countries have multiple timezones, some servers can be in one zone while the users can be in a different zone, and so on.
All the timezone information is stored in /usr/share/zoneinfo. The directories and files in there are definitions of what the displayed time should be. The displayed time is based on Coordinated Universal Time (UTC) adjusted to the rules listed in a timezone file in /usr/share/zoneinfo.
To modify the timezone for your computer; copy a timezone file to /etc/localtime. For example to set the timezone to Europe/Amsterdam:

# cp /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime

Chances are that your distribution has a tool available to help you. Use it; it's likely easier. Fedora uses a tool called system-config-time to manage time and timezones.

The good news

Most likely your Linux box is already prepared for DST. Above all that, Network Time Protocol (NTP) is so extremely easy to use, that syncing your time is no problem at all. To be prepared for DST, use NTP and update all packages on your Fedora machine like this:

# yum update
# yum install ntp
# service ntpd start
# chkconfig ntpd on

For any other distribution; update you system, install ntp and start it.

Google Apps problems

There seem to be some problems with Google Apps since approximately 11:00 CET on 24th of februari 2009. When you are trying to login, you'll get an error like this:

Server Error
The server encountered a temporary error and could not complete your request.

Please try again in 30 seconds.

The title bar reads:

502 Server Error

The issue is discussed in The Google support forum. Meanwhile, we will wait for Google Apps to be available again...

Update: The problem seems to be fixed! (14:00 CET)

About Consultancy Articles Contact




References Red Hat Certified Architect By Robert de Bock Robert de Bock
Curriculum Vitae By Fred Clausen +31 6 14 39 58 72
By Nelson Manning [email protected]
Syndicate content