Blog O' Matty


Bash short cuts / hotkeys

This article was posted by Matty on 2006-12-01 15:41:00 -0400 -0400

I use bash as my primary shell, and have come to rely on the following bash short cuts:

alt-f -- move forward one word
alt-b -- move backwards one word
ctrl-a -- takes you to the begining of the command you are currently typing.
ctrl-b -- move backwards one character
ctrl-c -- kills the current command or process.
ctrl-d -- kills the shell.
ctrl-e -- takes you to the end of the command you are currently typing in.
ctrl-f -- move forward one character
ctrl-h -- deletes one letter at a time from the command you are typing in.
ctrl-l -- clear screen
ctrl-r -- does a search in the previously given commands so that you don't have to repeat long command.
ctrl-u -- clears the typing before the hotkey.
ctrl-z -- puts the currently running process in background
esc-b -- takes you back by one word while typing a command.
esc-p -- like ctrl-r lets you search through the previously given commands.
esc-. -- gives the last command you typed.

Cron format

This article was posted by Matty on 2006-11-30 22:15:00 -0400 -0400

I’ve been cleaning out a bunch of super old notes this week, and am going to post them on my blog for future reference. In case I incur a head injury and need to memorize the crontab format again, here it is as ascii art:

minute (0-59),
| hour (0-23),
| | day of the month (1-31),
| | | month of the year (1-12),
| | | | day of the week (0-6 with 0=Sunday).
| | | | | command
0 2 0,4 /etc/cron.d/logchecker

You will probably see a few of these posts hit my blog in the days to come.

Creating a Linux ramdisk

This article was posted by Matty on 2006-11-30 22:12:00 -0400 -0400

While performing some testing a few weeks ago, I needed to create a ramdisk on one of my redhat AS 4.0 servers. I knew Solaris supported tmpfs, and after a bit of googling was surprised to find that Linux supported the tmpfs pseudo-file system as well. To create a ramdisk on a Linux host, you first need to find a suitable place to mount the tmpfs file system. For my tests, I used mkdir to create a directory valled /var/ramdisk:

$ mkdir /var/ramdisk

Once the mount point is identified, you can use the mount command to mount a tmpfs file system on top of that mount point:

$ mount -t tmpfs none /var/ramdisk -o size=28m

Now each time you access /var/ramdisk, your reads and writes will be coming directly from memory. Nice!

Rebuilding the RPM database indexes

This article was posted by Matty on 2006-11-29 23:00:00 -0400 -0400

The RPM indexes on one of my CentOS 4.4 machines got corrupted last weekend, which caused some issues on one of the servers I was trying to update. To fix this issue, I removed the files with two underscores in /var/lib/rpm:

$ rm -f /var/lib/rpm/__

And then I recreated the indexes by running rpm with the “–rebuild” option:

$ rpm --rebuild

This experience taught me a few things:

​1. The package header information is stored in /var/lib/rpm/Packages

​2. RPM has an “–initdb” option to initialize the RPM database

​3. I really don’t care for RPM

Monitoring logfiles with logsentry

This article was posted by Matty on 2006-11-29 22:35:00 -0400 -0400

I manage a fair number of servers, and use several tools to monitor the health of my systems. One such tool is logsentry (formerly known as logcheck), which is a shell script that can be used to monitor logfiles for anomalies. Logsentry consists of a single shell script and one or more violation files, and installing it as simple as extracting the package and modifying the paths in the shell script. If your using OpenBSD, you can use the pkg_add utility to add the logsenty package to your system:

$ export
PKG_PATH="ftp://ftp.openbsd.org/pub/OpenBSD/3.9/packages/i386/"**

$ pkg_add logsentry

` logsentry-1.1.1p2: complete`

--- logsentry-1.1.1p2 -------------------
The logsentry configuration files have been installed at
/etc/logsentry.
Please view these files and change the configuration to meet your
needs.

Currently logsentry will check the following files:

/var/log/messages
/var/log/maillog
/var/log/authlog
/var/log/secure
/var/log/daemon
/var/log/xferlog

Edit /etc/logsentry/logsentry.sh
if you want to add more files.

Be sure to configure your crontab as indicated by
/usr/local/share/doc/logsentry/INSTALL
so that logsentry is run regularly.

After logsentry is installed, you can add a cron job to enable it. Once logsentry is enabled, you will get email similar to the following each time an anomaly is detected:

from Charlie Root
to root
date Nov 25, 2006 1:00 PM
subject yappy 11/25/06:13.00 system check

Security Violations
=-=-=-=-=-=-=-=-=-=
Nov 25 16:25:57 yappy su: matty to root on /dev/ttyp0
Nov 26 05:18:40 yappy su: matty to root on /dev/ttyp0
Nov 26 05:22:10 yappy su: BAD SU matty to root on /dev/ttyp0
Nov 26 05:22:14 yappy su: matty to root on /dev/ttyp0

If logsentry emails you about an anomaly that your not interested in, you can add a string that matches the error to logsentry.ignore (this is used to filter out messages from the Unusual system events section) or logsentry.violations.ignore (this is used to filter out events from the security section). Logsentry works pretty well, and once the ignore files are adjusted to match the personality of the server, it can be a life saver (I like the fact that logsentry will send an email notifications when a hardware error is written to the system logfiles).