Quick Bash script for investigating reasons for NTP time drift on Linux VMware guests 0

I recently received a help desk ticket asking me to investigate the reason why a large number of RedHat VMware guests were not keeping their clocks in sync.  The Linux administrators were very confused, as the NTP service was running on the guests in question.

As you may or may not know, VMware has a published KB of timekeeping best practices for Linux guests.  It can be found under KB 1006427.  In the case of the guests I was asked to investigate, they did not have the VMware recommendations in place.  Once applied / rebooted, these guests had no problem keeping their clocks in sync.

To aid in the discovery of the necessary guest information, I quickly threw together this Bash script.  I figured I would post it here in hopes that it might help someone out there.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
 
## Author:  Tim Patterson (tim@pc-professionals.net)
 
## Time Drift Check ##
## Quick script designed to supply administrator with information regarding reason for NTP time drift on RedHat (or variant) hosts ##
 
cmd="uname -a; cat /proc/cmdline; cat /etc/redhat-release; echo 'NTP Status:'; /etc/init.d/ntpd status; echo 'VMware Tools version:'; grep '\$buildNr =' /usr/bin/vmware-config-tools.pl"
 
echo "Target VMware Tools version: '8.6.10 build-913593' (as of 06/10/2013)"
echo "See this KB article for desired kernel parameters: "
echo "http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1006427"
echo
echo
 
for host in $(cat hosts); do
        echo "Host: $host"
        ssh root@$host $cmd
        echo
        echo
done

Hosts file contains entries like:
host1.domain.com
host2.domain.com
hostX.domain.com

Output is as follows:

$ ./time-drift-check.sh
Target VMware Tools version: ‘8.6.10 build-913593’ (as of 06/10/2013)
See this KB article for desired kernel parameters:
http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1006427

Host: host1.domain.com
Linux host1.domain.com 2.6.9-67.0.15.ELsmp #1 SMP Tue Apr 22 13:50:33 EDT 2008 i686 athlon i386 GNU/Linux
ro root=/dev/SYSTEM/root rhgb quiet
Red Hat Enterprise Linux ES release 4 (Nahant Update 6)
NTP Status:
ntpd (pid 12487) is running…
VMware Tools version:
$buildNr = ‘8.3.7 build-381511’;

Host: host2.domain.com
Linux host2.domain.com 2.6.9-67.0.15.ELsmp #1 SMP Tue Apr 22 13:50:33 EDT 2008 i686 athlon i386 GNU/Linux
ro root=/dev/SYSTEM/root rhgb quiet
Red Hat Enterprise Linux ES release 4 (Nahant Update 6)
NTP Status:
ntpd (pid 6633) is running…
VMware Tools version:
$buildNr = ‘8.3.7 build-381511’;