Getting Net-SNMP to see your drives

It seems that the Net-SNMP snmpd daemon doesn’t always recognize a systems drives. I recently encountered this on some RHEL6 servers.

The solution is simple, add the follow option to the snmpd.conf file and restart snmpd.

includeAllDisks 1

This forces snmpd to monitor all the systems drives.

If you have NFS mounts, you may want to tell snmpd to ignore them with the following option.

skipNFSInHostResources 1

Another option is the disk option that allows you to specify specific drives instead on tracking everything.

You can read up on all these options and more in the snmpd.conf manpage.  The most recent version is available online at http://www.net-snmp.org/docs/man/snmpd.conf.html.

Sequences in Bash

If you do a fair amount of shell scripting in Linux, chances are you have found yourself needing to perform an action a specific number of times, or just looping through all the values in a range.

Here are some examples of how to create a sequence of numbers or letters for use in Bash shell scripts.

# Create a sequence of numbers
 $ echo {0..9}
 0 1 2 3 4 5 6 7 8 9
# Create a sequence of letters
 $ echo {a..z}
 a b c d e f g h i j k l m n o p q r s t u v w x y z
# In uppercase too!
 $ echo {A..Z}
 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
# Multiple sequences at once. Note the space between the groupings.
 $ echo {0..9} {a..z} {A..Z}
 0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
# Remove the space and you will create all the combinations.
 $ echo {0..9}{a..z}
 0a 0b 0c 0d 0e 0f 0g 0h 0i 0j 0k 0l 0m 0n 0o 0p 0q 0r 0s 0t 0u 0v 0w 0x 0y 0z 1a 1b 1c 1d 1e 1f 1g 1h 1i 1j 1k 1l 1m 1n 1o 1p 1q 1r 1s 1t 1u 1v 1w 1x 1y 1z 2a 2b 2c 2d 2e 2f 2g 2h 2i 2j 2k 2l 2m 2n 2o 2p 2q 2r 2s 2t 2u 2v 2w 2x 2y 2z 3a 3b 3c 3d 3e 3f 3g 3h 3i 3j 3k 3l 3m 3n 3o 3p 3q 3r 3s 3t 3u 3v 3w 3x 3y 3z 4a 4b 4c 4d 4e 4f 4g 4h 4i 4j 4k 4l 4m 4n 4o 4p 4q 4r 4s 4t 4u 4v 4w 4x 4y 4z 5a 5b 5c 5d 5e 5f 5g 5h 5i 5j 5k 5l 5m 5n 5o 5p 5q 5r 5s 5t 5u 5v 5w 5x 5y 5z 6a 6b 6c 6d 6e 6f 6g 6h 6i 6j 6k 6l 6m 6n 6o 6p 6q 6r 6s 6t 6u 6v 6w 6x 6y 6z 7a 7b 7c 7d 7e 7f 7g 7h 7i 7j 7k 7l 7m 7n 7o 7p 7q 7r 7s 7t 7u 7v 7w 7x 7y 7z 8a 8b 8c 8d 8e 8f 8g 8h 8i 8j 8k 8l 8m 8n 8o 8p 8q 8r 8s 8t 8u 8v 8w 8x 8y 8z 9a 9b 9c 9d 9e 9f 9g 9h 9i 9j 9k 9l 9m 9n 9o 9p 9q 9r 9s 9t 9u 9v 9w 9x 9y 9z
# You can generate a sequence in reverse too!
 $ echo {9..0}
 9 8 7 6 5 4 3 2 1 0

Find’s “or” option

I work with a group of web servers that regularly need to have their /tmp directories cleaned up.  At first we tried the following find(1) command:

/usr/bin/find /tmp -maxdepth 1 -type f -iname '*.jpg' -or -iname '*.gif' -or -iname '*.bmp' -or -iname '*.png' -or -iname '*.pdf' -or -iname '*.bmp' -print0 -mmin +1440 | xargs -r -0 rm -rf

While it looked right, no files were being removed.  Going back to find(1)s man page I noticed a key word, expression.

So what is a find(1) expression?  A find(1) expression is made up of two parts, what your looking for and what you want to do with it. “-iname ‘*.bmp’” only matched half of the requirements.

Adding the “what to do” part to each expression, the find command now looks like:

/usr/bin/find /tmp -maxdepth 1 -type f -iname '*.jpg' -print0 -mmin +1440 -o -iname '*.gif' -print0 -mmin +1440 -o -iname '*.bmp' -print0 -mmin +1440 -o -iname '*.png' -print0 -mmin +1440 -o -iname '*.pdf' -print0 -mmin +1440 | xargs -r -0 rm -rf

Now find is listing the files which are being fed into xargs/rm for deletion.

Installing vmware-tools in FreeBSD 9

I recently tried to install VMWare’s tools into a 64-bit FreeBSD in VMware Workstation 8.  I was unable to get the tools provided by VMware to install.  A quick Google search showed this is a common problem.

The solution is to use the VMware tools provided in the ports collection.  Even this method requires some minor tweaking though.

The process:

  1. If you haven’t already, install the ports collection.
  2. From VMware Workstation’s VM menu (right-click in Vsphere), choose “Install VMware Tools…”.
  3. In the FreeBSD VM, determine which device is your CD drive.  It’s always been /dev/cd0 in my VMs but you’ll want to double-check.
  4. Before installing the VMware tools port, you need to update the Makefile /usr/ports/emulators/vmware-guestd6/Makefile.  Update the line MOUNT_DEV? = /dev/ad0 to point to your cdrom.  Mine looks like MOUNT_DEV? = /dev/cd0
  5. Change to the /usr/ports/emulators/vmware-tools6 and run the make command.  You’ll be prompted to continue.  Say yes.

If all goes well, the port will access the cdrom, grab some files, download more files and build the tools.  The tools are installed in /usr/local like most ports.

If you plan to run X11, you may also want to install the VMware X11 driver in /usr/ports/x11/drivers/xf86-video-vmware.  It will install the Vmware specific video driver.

03/05/2012 Update:  After few reboots, the errors returned.  See this post in the VMware forums for details: http://communities.vmware.com/message/1893843

 

Switch to our mobile site