Linux tips & techniques for developers and system administrators.


Modifying Windows Multimedia keyboard volume keys

By jbayer - Last updated: Thursday, May 29, 2014

I recently got a new keyboard, and wanted to use the volume keys.  They worked, but only changed the volume by 2% for each keystroke;  I determined that by setting the volume to 0 and then counting how may keystrokes it took to get to full volume.

While Windows recognizes the volume keys, after extensive searching I couldn’t find any way to adjust the amount of change for each key.

I did find a solution, using a scripting engine called AutoHotKey, available at:

I found a minimal script which needed work, but finally does what I want.  You will need to install this script in a folder with the following library:

The script which I wrote intercepts the keys and adjusts the volume.  If you just call it with no parameters, it will use a value of 5 for the delta amount.

If you put a value on the cmd line, it will use that value as the delta.

If you put any other text on the cmd line, it will open a small dialog asking you for the delta.

When you hit the up or down volume key, it will adjust the volume by the specified delta, and then play a tiny sound to let you hear what the current volume is.

Here is the script as I have it working now:

#SingleInstance force
#Include %A_ScriptDir%\VA.ahk

delta := 5
if 0 = 1 ; If a parameter is passed in, use that for the volume delta
 index = 1
 if %index% is integer
 delta := %index%
 if %index% is not integer
 InputBox, delta, Volume Delta, Enter Volume Delta
 if ErrorLevel
 delta := 5
if delta = ""
 delta := 5
 SoundPlay *-1
MsgBox Volume Delta is %delta%

 newVol := VA_GetMasterVolume() + 5
 SoundPlay *-1

 newVol := VA_GetMasterVolume() - 5
 SoundPlay *-1

Filed in AutoHotKey, Programming, Windows

Updated Zabbix install script

By jbayer - Last updated: Saturday, May 3, 2014

My latest version of the install script, with the following additions:

Fixed missing install of libxml2-devel


Make sure that wget is installed before running the script.


  install_zabbix.tar.gz (17.2 KiB, 0 hits)

Filed in Administration, Zabbix

Starting & stopping CF-Engine

By jbayer - Last updated: Wednesday, January 15, 2014

We are slowly implementing CF-Engine 3 in our environment.  Inevitably, there are occasionally problems on specific systems.  Sometimes we need to disable CF-Engine while debugging since the files that are being worked on are maintained by CF-Engine and would be overwritten during the debugging process.

We also put a line in to /etc/cron.d/cfengine to restart it if for some reason it is stopped.

I wrote the attached script which will disable both cf-monitord and cf-execd, and set a flag so that it won’t be started by the cron entry.  Actually, the cron entry calls the script to CF-Engine if it is not running.

The only line which might need to be changed is the FLAGDIR, which specifies where to put the flag file.

# usage:
# [disable | enable | runcheck]
#      disable      set disable flag, and stop cf-execd and cf-monitord
#      enable       remove disable flag, and start cf-execd and cf-monitord
#      runcheck     check to see that both cf-execd and cf-monitord are running
#      anything else, or nothing, just shows the current state


This is the cron entry (put it in /etc/cron.d/cfengine):

# Ensure that cf-execd and cf-monitord are running
*/5 * * * * root /usr/local/sbin/ runcheck


  cfengine.tar.gz (2.2 MiB, 396 hits)


Filed in Administration, Bash, CF-Engine

Updated (again) Zabbix install script

By jbayer - Last updated: Sunday, November 3, 2013

My latest version of the install script, with the following additions:


Changed to require custom version of checkinstall
Now adds OS version to RPM names

Fixed bug in script when using new version of checkinstall (17.1 KiB, 0 hits)

Filed in Zabbix • Tags: ,

Updated checkinstall for Redhat 5 & 6

By jbayer - Last updated: Monday, October 14, 2013

I’ve consolidated the changes I’ve made into a new release:

Added ability to remember options between runs
Added –os option to specify OS release (ie: el5)

Due to the different libraries between OS releases, I have a version for Redhat 5 and another version for Redhat 6


  checkinstall- (155.0 KiB, 410 hits)

  checkinstall- (293.3 KiB, 512 hits)

Filed in Building packages, Open Source • Tags: ,

Updated Zabbix install script

By jbayer - Last updated: Monday, October 14, 2013

My latest version of the install script, with the following additions:

1.9 Added check for latest zabbix version

Added postfix to install

1.10 Updated paths for changes in Sourceforge

Added mod_ssl to Apache install
Updated version number for epel

1.11 Added Postgresql database option

Changed to require custom version of checkinstall
Now adds OS version to RPM names (16.9 KiB, 557 hits)

Filed in Building packages, Zabbix • Tags: , ,

SSH known_hosts Management with CFEngine

By jbayer - Last updated: Thursday, October 10, 2013

For small sites, a changed Secure Shell (SSH) host key poses only minor problems, as only a few systems might be affected. At larger sites, the host key data should be maintained with configuration management, so that any SSH host key changes can be propogated throughout the site. CFEngine can maintain a global ssh_known_hosts file for OpenSSH.

Host Key Collection with ssh-keyscan

The global ssh_known_hosts file should be maintained under version control. I keep the file atmasterfiles/ssh/ssh_known_hosts under the repository, and use a set of scripts around ssh-keyscan(1) to add or update host keys manually. When collecting host keys from other servers, care should be taken that no attacker has supplied a malicious key. The man-in-the-middle threat can be reduced by using an authoritative name server on the system running ssh-keyscan(1). Also, have each system compare its own keys with the keys the scanning system collected, and alert if differences appear.

Scripts to assist key collection include:

With a Makefilemake add or make update can be used to update the host key list:

# usage:
# echo hostname | make add
 @expand-hl | add-ssh-hostkeys ssh_known_hosts

 @update-ssh-hostkeys ssh_known_hosts


Distributing ssh_known_hosts

Use a remote_dcp bundle to distribute the ssh_known_hosts file, with variables to account for vendor specific differences.

 "ssh_known_hosts" string => "/etc/ssh_known_hosts";
 "ssh_known_hosts" string => "/etc/ssh/ssh_known_hosts";
   handle => "ssh_known_hosts",
   comment => "Copy ssh_known_hosts file",
   create => "true",
   perms => mog("0444", "root", "root"),
   copy_from => remote_dcp("${masterfiles}/etc/ssh/ssh_known_hosts", "${policyhost}"),
   classes => if_repaired("ssh_known_hosts_file_modified");

Users with old host keys in their ~/.ssh/known_hosts files will see key warnings. Old keys must be deleted in favor of the globally maintained keys.

The inspiration for this post is, which is for CF-Engine 2.  Unfortunately, the email for the author is not valid anymore.

Filed in CF-Engine • Tags: , ,

Usin JSON to add a new host in Zabbix 2.0

By jbayer - Last updated: Wednesday, October 2, 2013

This script was originally written by Travis Mathis, from Millicorp back in 2011, for Zabbix 1.8.5.  A link to the original posting on the Zabbix forum is

Zabbix Agent/Host Auto Install/Create Script using API


I’ve updated the script to work for Zabbix 2.0 (tested with 2.0.8 and on CentOS 5/6). I’ve also added a number of command-line options to allow this to be run automatically, converted many sections to functions, added ability to specify multiple templates, added ability to specify multiple groups, added IP address validation
-l location
-h hostname
-i ip address
-g group name (if spaces, must be inside quotes)
-t template name (if spaces, must be inside quotes)
-d dry run (prints out a complete command line)
-q quiet (reduces output)

All parameters are optional.  If a value is not specified on the command line, the script will prompt for the value.

Other than checking to verify that a syntactically valid IP address is entered, there is no error checking. If the system has multiple IP addresses, it will select the first one (as returned by ifconfig)

The script has the ability to install the agent which I don’t use; we use CF-Engine to install standard packages on our systems.  However, if you would like to use this to install the agent as well, there are a couple of minor changes you will have to make:

  1. The variable “INSTALL_AGENT” will need to be set to 1
  2. The function “addZabbixRepo” will need to be updated to whatever repo you want to use.
  3. The function “install_agent_and_add_port_to_iptables” may need to be modified to install the correct agent packages.
  4. If you want it to install a basic config file for zabbix, you will also need to update “INSTALL_CONF” and “ZABBIX_CONF”

The dry run option is intended to be used to generate a complete command line which you can then use in a script. (4.0 KiB, 1,328 hits)



Filed in Zabbix • Tags: , ,

Find big files

By jbayer - Last updated: Wednesday, October 2, 2013

Someone is using a lot of space, and you want to find out who.  More specifically, you would like to identify the large files and automatically send them an email about it.

This script will do that for you.  It’s called findbig, and can be called by hand or from a cron job.  It will only send one email to a user, with a list of all large files in it.  It sends mail to the local user account, if you want the user’s mail sent to a different address, you will have to either edit the file or use the /etc/aliases file to redirect the email.

The parameters are:

findbig [ - a age ] [ -c ] [ -m addr ] [ -l log ] [ -u ] [ -d ] [ -s size ] [-e dir] [-x filename] [dir [size] ]
-a age   Minimum age, in days
-c       console mode, echo all messages to screen
-d       Debug mode
-s size  Minimum size of files to report
-e dir   Directory to exclude
-m addr  Email address to send all messages to
-l log   Append results to this file
-u       Send mail to owner
-x filename filename containing directories and files to exclude. The file contains
one path or file per line. Directories are identified by a trailing slash
Comments begin with a pound sign (#)
dir Directory or file to work on
size Minimum size of files to report. Suffixes are allowed (k for K, m for meg,
g for gig, t for tera). Both lower and upper case are allowed



An example (broken up onto 2 lines):

findbig  -a 10 -m -e /var/lib/libvirt/images \
         -e /proc -l /home/jbayer/bin/test.log  -u  / 10g

And this does the following:

  1. Send emails to me of found files
  2. Send emails to the owner of the file
  3. Exclude the following directories:
    1. /var/lib/libvirt/images
    2. /proc
  4. Log results in the file /home/jbayer/bin/test.log
  5. Start in the / directory
  6. Find all files bigger than 10 gig in size, and at least 10 days old


  findbig.tar.gz (2.2 KiB, 403 hits)

Filed in Bash • Tags: ,

Copying or Backing up an image of an LVM-based Virtual Machine

By jbayer - Last updated: Wednesday, October 2, 2013

If you are using virtual machines on a Linux system, you may be storing the VM image in an LVM partition.  This can make it difficult to copy or backup an image of the VM.

The attached script will do just that.  It displays the list of VMs running on the system and allows you to select which one to copy.  If the VM is currently running, it will optionally shut it down before doing the backup;  if it can’t or you don’t want it to shut it down, it will wait for you to shut it down manually.  When complete, it will optionally restart the vm (if it had been running when the script started) and compress the image file if desired.

The only hard-coded value is the DESTDIR, which is where the images are stored.

The script will NOT backup image files. (1.1 KiB, 443 hits)

Filed in Backup, Open Source, Virtulization • Tags: , , ,