[Blue Ribbon Campaign icon]

   get back!    get down!   

code

This software is free.

Some more scripts are here, including changes, the most simple version control system I know of:

ecashin@kokone tmp$ mkdir project
ecashin@kokone tmp$ cd !$
cd project
ecashin@kokone project$ for c in a b c; do echo $c > $c; done
ecashin@kokone project$ EDITOR=ed changes rec
/tmp/project/../project.changes/desc/1: No such file or directory
a
initial import
.
wq
15
ecashin@kokone project$ changes log
1       20051213-114449
        initial import
ecashin@kokone project$ 
ecashin@kokone project$ echo new line >> a
ecashin@kokone project$ EDITOR=ed changes rec
/tmp/project/../project.changes/desc/2: No such file or directory
a
added a new line to file a
.
wq
27
ecashin@kokone project$ changes log
2       20051213-114547
        added a new line to file a
1       20051213-114449
        initial import
ecashin@kokone project$ changes diff
ecashin@kokone project$ echo another >> b
ecashin@kokone project$ changes diff
diff -X /tmp/project/../project.changes/dontdiff -uprN /tmp/project/../project.changes/trees/2/b ./b
--- /tmp/project/../project.changes/trees/2/b   2005-12-13 11:44:38.000000000 -0500
+++ ./b 2005-12-13 11:46:17.000000000 -0500
@@ -1 +1,2 @@
 b
+another
ecashin@kokone project$ changes diff 1 2
diff -X /tmp/project/../project.changes/dontdiff -uprN 1/a 2/a
--- 1/a 2005-12-13 11:44:38.000000000 -0500
+++ 2/a 2005-12-13 11:45:40.000000000 -0500
@@ -1 +1,2 @@
 a
+new line
ecashin@kokone project$ 

bkp
bkp

This simple script is something you can run right before you run vi. It creates a dated backup of files, avoiding conflicts with other files.

[ecashin@hosty ecashin]$ bkp /tmp/testfile
bkp "/tmp/testfile" --> "/tmp/testfile.20010608"

[ecashin@ember ecashin]$ bkp /tmp/testfile /tmp/testfile-bar
bkp "/tmp/testfile" --> "/tmp/testfile.20010608_1"
bkp "/tmp/testfile-bar" --> "/tmp/testfile-bar.20010608"
uniq-mbox
uniq-mbox

This script uses formail and procmail to remove duplicates from a UN*X mailbox file. Read it before using it, and always make backups of your mailboxes before using tools like this.

[ecashin@hosty ecashin]$ uniq-mbox /tmp/ecashin-mbox.uniq < /var/mail/ecashin
mail is in /tmp/ecashin-mbox.uniq
duplicates are in /tmp/dupsAZO8Qa
kernel source to postscript digger
kern-ps  is a ruby script that formats a kernel source file and all of the headers it includes, directly and indirectly, as postscript using vgrind. (So you need vgrind and ruby to use it.)

It produces one postscript file for each source file. You may combine them with the related tool below, kern-ps-merge.

See script for simple usage and example.

kern-ps-merge combines kern-ps output files into one postscript file
kern-ps-merge  is a ruby script that combines the many files created with kern-ps into one postscript file.

See script for simple usage and example.

oinst software installation management tool
oinst uses hardlinks to make it easy to provide central access to software installed from source without sacrificing modularity and ease of installation/uninstallation.

I have not used oinst in a while. I like this better: install source-built programs in a fully-versioned directory in /opt, like "/opt/tla-1.0.1". Then create symlinks as necessary in /opt/bin and /opt/man, etc. It's not much pain, because I only have to symlink the stuff I use enough to need it in my $PATH.

dependency generator for make
depgen  outputs makefile rules for each C file it examines. You can then include the generated list of make rules into other makefiles.

This script was created when I was trying to please as many different versions of make as possible. I decided to avoid pattern rules and suffix rules entirely.

You use it as follows and then do "include dep.mak" in your makefile.

depgen *.c > dep.mak

You must define the makefile variables ${srcdir} and ${COMPILE} with something like this in your makefile:

srcdir = .
WARNINGS = -Wall -W -Wtraditional -Wundef -Wshadow -Wid-clash-30 -Wpointer-arith \
	 -Wbad-function-cast -Wcast-qual -Wcast-align -Wwrite-strings \
	 -Waggregate-return -Wstrict-prototypes -Wredundant-decls -Wnested-externs
CFLAGS = -g3 
COMPILE = ${CC} ${CFLAGS} ${WARNINGS} -c 
host access rules for mini_httpd
This patch adds IP-based access control to Jef Poznaker's mini_httpd.

mini_httpd is a small web server that can do SSL. My patch applies against mini_httpd version 1.17beta1. After applying the patch and editing the makefile to point to your configuration file, you can configure mini_httpd to accept or refuse connections based on IP, using a configuration file like this:

accept:128.192.1.9
accept:192.168.0.0/16
deny:127.0.0.1/8
deny:

As you can guess, this configuration allows connections from host 128.192.1.9, and from any IP beginning with 192.168, regardless of the second half of the IP. (The first 16 bits of the 32-bit address are significant.) It doesn't accept connections from anyone else. The empty address after the last "deny" is equivalent to "0.0.0.0/0".

Please let me know if you use this patch — I'd like to hear feedback.

re2c extensions
scanner.c and scanner.h provide support to the re2c scanner generator. There's an example of how to use these files embedded in scanner.c ... it's the lex function between "#if 0" and "#endif".
addkeys
addkeys

addkeys is a ruby script that runs ssh-add for you.

It asks you for your passphrase and tries to use that passphrase to add all the keys listed on the commandline.

It's a good example of using the pseudo-tty and readline ruby extensions.

You use it like this:

addkeys ~/.ssh/identity ~/.ssh/id_dsa

And it will probably be most conveniently used from an alias defined in your shell startup file:

# .bashrc
alias addkeys='command addkeys ~/.ssh/identity ~/.ssh/id_dsa'
taterlogs
taterlogs and skeleton taterlogs.conf file

taterlogs is a portable, simple log rotation script written in perl with compression support and support for commands to run after rotation.

Unlike Linux's logrotate, taterlogs only runs a given post-rotate command once, so if you have lots of logs created by one daemon, e.g., syslogd, then that daemon only gets HUP'ped once.

The configuration file is very simple. You can use aliases for complex commands to keep it readable and maintainable

Do "taterlogs --help" to get usage info.

qmanip
qmanip

This ruby script has a similar function to the script, "qtool.pl", which comes in the sendmail distribution's contrib directory. It allows a sysadmin to manipulate live mail queues without shutting down sendmail.

The way that's possible to do safely is that qmanip, like qtool.pl, uses the same kind of file locking that sendmail itself does.

Do "qmanip --help" to get usage info or click here.

integrit
The integrit file verification system is a project housed at Sourceforge that is for intrusion detection. (Like several of these tools, it was not created using UGA property or as a work assignment at UGA.) Its design goals include simplicity, security, convenient unattended operation, and a small memory footprint.

(If the sourceforge homepage is unavailable, there's also a local location for downloads.)

I wrote it because I use intrusion detection systems at work to determine whether or not our servers have been compromised, and of the two systems we use, both are overly complex and both take up a lot of memory at runtime, but one is bloatedly complex and the other has a whopping great memory footprint that has no runtime limits and could take down a server.

Some interesting things:

bin2c
bin2c (AKA bin2h)

For compiling binary data, e.g., images, into a C program.

Reads in a binary and creates C code on standard output that has a character array that holds the binary data.

I wrote this program because I found similar programs (often called bin2h) that had arbitrary limits on the size of data.

Syncotron Bathysphere Sound Suite
The Syncotron Bathysphere Sound Suite is a project housed at sourceforge that uses a distributed design to create an interactive sound environment.
mboxsize
mboxsize is a UN*X tool for showing the size of individual messages inside of a UNIX-format mailbox file. In addition to the size in bytes, it displays the contents of the subject, from, and date headers.

It has a variety of output formats, including XML and line output with user specified field delimiters:

It can reset the access time of the mailbox it reads. (So that finger info about the time the mail was last read doesn't get messed up.)

usage:
    mboxsize [ -h | -r | -x | -D | -d DELIM ] [-a] [mbox]
options:
    -h show this help
    -a reset access time
    -r use multi-row output format
    -x use XML output
    -D set output delimiter to "|--|"
    -d set output delimiter to DELIM

The default output format looks like this:

2849   Re: multi-column spread Ed L Cashin <ecashin@co 13 Nov 2000 13:43:06 -05
2140   Re: multi-column spread Ed L Cashin <ecashin@co 13 Nov 2000 13:44:19 -05
2126   Re: M-Math; \placeformu Tobias Burnus <burnus@g Mon, 13 Nov 2000 21:25:4
2271   last questions, urgent  Hraban <angerweit@gmx.n Mon, 13 Nov 2000 21:56:3
2392   Re: beginner's question siepo@cybercomm.nl      Mon, 13 Nov 2000 22:26:0
8382   Re: Fwd: Re: beginner's siepo@cybercomm.nl      Mon, 13 Nov 2000 22:26:3

mboxsize is a good example of a simple program that uses a fast scanner generated by flex for its lexical analysis

That just means that instead of writing C code to look through the mailbox, I wrote a short list of regular expressions and corresponding actions in an input file for flex. flex generates optimized C code to look for the patterns that I specified.

An alternative to flex is re2c. It generates even faster C scanners than flex does. It's more flexible than flex, but it takes a bit of getting used to.

logrun
logrun

This is a very simple C program that can be configured to act as a wrapper that sits in the place of a program (e.g. /usr/local/bin/slirp) and syslogs each invocation before exec-ing the real binary, which lives in another obfuscated directory.

It's for lightweight, unobtrusive, selective accounting.

resume
resume is a generic resume written for the ConTeXt macropackage.

This code uses ConTeXt macros to describe a document, and ConTeXt uses pdfTeX behind the scenes to create a really nice looking resume.

Because this resume uses some cutting-edge ConTeXt features, it has a short HOWTO explaining how to upgrade pdfTeX and ConTeXt in a UNIX teTeX installation.

Match
Match (formerly called "Regexp") is a small Objective-C class that encapsulates POSIX regular expression support. It is free software.

It will compile with gcc and includes an example of its use (main.m). You can build the example by typing "make" in the unpacked Match directory.

Besides being handy, it's a good demonstration of how to use the standard C libary's regular expression support and also of how to make an Objective-C class.

hashtbl
hashtbl is a simple hash table package in C.

Its structure is loosely based on the examples in K&R2, its hash function is from cdb, a database by the smart D. J. Bernstein, and with optimizations based on glib.

It's mostly ANSI C. "inline" is part of the new C99 standard, but if your compiler doesn't support the "inline" keyword, just do this to make the compiler ignore it:

#define	inline
xstradd
xstradd has a couple of C functions for adding together an arbitrary number of strings.

To use:

char	*oldstr	 = "an old string";
char	*newstr	 = xstradd("This is ",
			   __FUNCTION__,
			   " so fun (",
			   oldstr, ")",
			   NULL);

puts(newstr);	/* use newstr */

free(newstr);

It's more interesting because it uses the Boehm garbage collector for finding memory leaks.

FreqSpec and the samplomatic
FreqSpec.h and FreqSpec.m are the header and implementation files, respectively, for a frequency analyzer written in Objective-C.

I used the POC to pre-compile the Objective-C into C code, but you could also use gcc (I bet). The current version of FreqSpec is part of the samplomatic, which does compile with gcc.

FreqSpec uses the Fastest Fourier Transform in the West (FFTW) library for the actual Fourier transforms. The library is interesting because it is self-optimizing: it creates an algorithm on the fly based on the idiosyncrasies of the machine it happens to be running on.

To use, you set it up and then send it a zero-terminated array of frequencies for the bands you want. If you are reading this with interest, contact me (see my home page for contact info), and I'll put more info here.

backup.sh
backup.sh is a (Bourne) shell script that uses tar to write backups to your SCSI tape drive.

The nice thing about this script is that it uses the ability of SCSI tapes to "tell" and "seek" block positions on the tape. backup.sh prints a list of block numbers so that you can ...

# seek the position of the tar dump for /var (known from backup.sh)
mt -f /dev/nst0 seek 658100
tar xvf /dev/nst0 var/log/secure

Here's a robust way to print the index from backup.sh:

tmp=$HOME/.tar_backup.tmp
nice -n 18 /adm/tools/backup.sh > $tmp && mpage -4 < $tmp | lpr || {
      echo error with backup.sh, see $tmp.  exiting. 1>&2
      exit 1
}

This article for Sysadmin Magazine extends this idea to multiple machines on a network.

Berend de Boer has made contributions to the solution described in the Sysadmin article. They're on the papers page.

code_print
code_print is a perl script that uses TeX, along with the eplain TeX macros and dvips, to print source code. You could do it without the script, but it is kind of tricky to get it right. The script handles it for you and makes it convenient.

This used to be true, but now I have found that the ConTeXt macro package has a \typefile command that works nicely, and emacs has a "ps-print-buffer" function that works very well.

norepeatogrep
norepeatogrep is a program written in C as a drop-in replacement for egrep as used in the logcheck system.

It is different in that it recognizes repeating log entries, and if there is an ignore rule for a given message, e.g.,

sshd.* log: RSA key generation complete.
... and there is this in the log:
Mar 16 23:08:24 schmu sshd[30386]: log: RSA key generation complete.
Mar 13 14:43:34 schmu last message repeated 18 times
Mar 13 14:43:34 schmu last message repeated 4 times
Mar 13 14:43:34 schmu last message repeated 2 times
... then "nrgrep" will ignore all four lines. Other, non-ignored lines, get printed out along with any "last message repeated n times" messages.

Let me know if you are interested in this and I'll clean it up and document it.

encapsul.pl
encapsul is a perl script that shows a simple demonstration of perl's data encapsulation support. This file shows a rudimentary object in perl. Perl's support for Object-Oriented Programming is very flexible and not very strict.

You can do things like multiple inheritance or no-no's like getting at the object's internal data directly bad coder! :(

xml2tex
xml2tex is a perl script that uses the nifty perl module, XML::Parser. It takes XML documentation as an input and produces plain TeX code that can be read by TeX or pdfTeX to produce .dvi, postscript, or PDF-format documents. Here is an example XML document.
It has embedded documentation, so just say:
perldoc /path/to/xml2tex 
utxreader
utxreader is a C program that can display the contents of arbitrary wtmpx-format binary files. wtmpx or utmpx is the format that the "last" facility on UNIX-like systems uses.
utxreader.c
usage:
	utxreader {filename}
example:
	utxreader /var/log/wtmpx | less
utxsplit
utxsplit is a C program that can read select records from arbitrary wtmpx-format binary files and write those records to a new wtmpx file. wtmpx or utmpx is the format that the "last" facility on UNIX-like systems uses.
utxsplit.c
usage:
	utxsplit {-b beginning_record} {-e ending_record} \
		{-i infile} {-o outfile}
example:
	utxsplit -b 51 -e 100 -i /var/log/wtmpx -o 51-100.wtmpx
gpl.pl
gpl.pl is a perl script that adds a commented GPL header to source files. Currently, it can do C-style and script style ("#") commenting. Type ./gpl.pl -h for usage.
I have to call the file gpl.perl because of the way our server works.
joe random
The Joe Random Sequencer is a C program that compiles with djgpp into a 32-bit DOS application. It plays wav files as samples with random pitch, volume, panning, and timings. You can turn off the randomness or limit it to a given range for any attribute of any sound.

get up!