Version française

Vincent Lefèvre's Unix Page

Some of my Utilities for Unix

These utilities are free. Check the license in each of them. There is no guarantee, and use them at your own risk.

check-eth-speed

Shell script to get and/or check the Ethernet speed, in particular useful to check by cron that the Ethernet speed hasn't been reduced (e.g. because of dust or a bad cable).

cwdiff

Zsh function/script that can be used as a wrapper to François Pinard's GNU wdiff utility in order to have colored output with a default setup, easy to change. Moreover, the wdiff -d option is implied when there are no arguments, and when there are differences (generally expected in this context), the exit status 1 is changed to 0 (meaning no errors).

dlogin [obsolete]

Zsh script to connect to a remote machine with the rlogin protocol and set the DISPLAY variable. The .zshenv, .cshrc or equivalent file on the remote machine needs to be modified accordingly. This script can now be used as an autoloaded function.

Note: For security reasons, the SSH protocol (command ssh or slogin) should now be used instead of rlogin; however the link is kept, as dlogin can be used as a simple example of Zsh script.

dobatches

Perl script to run batches from a shared directory. I wrote this program as a very simple and limited remplacement of the qsub command. Example of usage:

$ dobatches 'batch-.*' arg1 arg2 arg3

As you can see, the first dobatches argument is a regular expression, not a file pattern (i.e., write .* instead of *).

eet

Perl script providing advanced stream filtering and redirection to several files. Supplied in the archive below: a filter to colorize the output of make, and shell scripts to send the warnings to an xterm or zenity window.

Download: eet.tar.xz (signature); eet.tar.lz (signature); eet.tar.bz2 (signature).

efing

Perl script giving information about local users. I wrote it because the finger command (on Solaris) was too slow and buggy; I took the opportunity of giving some additional pieces of information. This script was first written for Solaris and NIS+, then modified to run on some versions of Linux and OSF1; it will not work on some systems. Man page for efing (nroff format).

fwdmail

Perl script forwarding mail messages by SMTP to some given address. It does not use the local SMTP client (generally invoked as sendmail), so that the local queue can be bypassed (this is useful if it is full of mailer-daemons due to some spam attacks). Documentation in the POD format is included in the script.

[2012-07-17 update] Mail files larger than some given size can be ignored (and kept in the queue). This option is useful when the mail is received on a laptop temporarily connected with a dial-up or GPRS/3G connection.

gccheaders

Zsh function/script that outputs all the header files included by gcc. See the page dedicated to gccheaders.

HTML5ToLibXML.pm

Perl module transforming a HTML5 document (provided as a string) into a LibXML document. It uses HTML::Gumbo and XML::LibXML.

idle

Perl script displaying idle times for kbd, mouse, the tty's and the pts (pseudo-ttys). This program may not work correctly on every system. However it has been tested on some versions of Solaris, Linux, OSF and Mac OS X. Man page for idle (nroff format).

Updated on 23 April 2006.

idlexec

Perl script to temporarily and automatically stop calculation processes that run on desktop machines, when someone uses a machine. Indeed some machines make a lot of noise when their processor is busy. This utility can take into account the fact that there can be several machines in a room. See the page dedicated to idlexec.

Perl script to create or update symbolic links to static libraries. This script may be useful to compile and link programs that do not provide a configure script, only a Makefile, and need to link with static libraries (for efficiency reasons), e.g. BaCSeL. The reason is that for compilation and conventional linking, one can use environment variables, such as C_INCLUDE_PATH, LIBRARY_PATH and LD_LIBRARY_PATH, but when one wants to link with a static library, one needs to either provide the full path to the library file or use non-standard compiler flags in the Makefile, i.e. which may not work on some platforms. This script makes the (recommended) former method a bit easier.

Example with BaCSeL:

$ ./liblinks lib libgmp.a libmpfr.a
$ make GMP=. DEFS="-DUSE_DPE -DZUSE_MPZ -DVBSE -DAUTOMATIC"
makefilter

Perl script colorizing the output of the make command. If your shell is zsh, you can use it automatically by adding the following line to your .zshrc:

make()
{
  local -a pstatus
  command make "$@" |& makefilter
  pstatus=($pipestatus)
  # If make has failed, return its exit status.
  [[ $pstatus[1] -eq 0 ]] || return $pstatus[1]
  # If eet has failed, return 125; otherwise return 0.
  [[ $pstatus[2] -eq 0 ]] || return 125
}

Warning if you want to compile a Linux kernel! This will make make menuconfig fail with a strange error message (the makefile is poorly designed, IMHO).

pdfcrush

Shell script to recompress a PDF file with Ghostscript's ps2pdf utility: recompressed fonts can sometimes make the PDF much smaller, but bitmap images are recompressed too in a lossy way (this can be controlled with the GS_OPTIONS environment variable). If available, the pdftk utility is used to restore the metadata (lost by ps2pdf), but warning! The official pdftk 1.41 is broken; Debian has a patch (handle_utf8_data_in_update_info). Also, as the PDF is generally a generated file, pdfcrush overwrites it with the recompressed version, but note that under some cases the recompressed version is bigger and/or may not look the same; make sure you have a backup version if needed.

Note also that on some PDF files (obtained with pdflatex), ps2pdf may corrupt the text part.

pdfdiff

Small Zsh script to output a textual diff between two PDF files for a text terminal (with colors). It depends on the pdftotext utility, and also on my tdiff script mentioned below. It basically consists in the following command:

tdiff "$@[1,-3]" <(pdftotext "$@[-2]" -) <(pdftotext "$@[-1]" -)

In order to have the completion in Zsh for this utility and for pdfwdiff (see below), it suffices to add a _pdfdiff file in the fpath, containing:

#compdef pdfdiff pdfwdiff

local cpdf='_files -g "*.pdf"'
_diff_options diff ":original file:$cpdf" ":new file:$cpdf"
pdfwdiff

Small Zsh script to output a word-diff between two PDF files for a text terminal (with colors). It depends on the pdftotext and wdiff utilities (with the recommended cwdiff wrapper).

pmchecker

Perl script checking that a procmailrc file (supplied as argument or on the standard input) is correctly formatted and does not contain suspicious constructs. In case of failure, pmchecker returns with a non-zero exit status and outputs a message to the standard error. This does not mean that there is really an error in the file, but one needs to be a bit paranoid to avoid losing mail (this occurred twice in my case, before I wrote this script). Of course, pmchecker can't detect all errors, but a missing continuation backslash or a bad use of < or > before a regular expression should be detected in general.

Users who manage their procmailrc files with Subversion may want to use this script in a pre-commit hook, e.g.

for i in `$SVNLOOK changed -t "$TXN" "$REPOS" | \
          sed -n 's/.* \(.*procmailrc.*\)/\1/p'`
do
  $SVNLOOK cat -t "$TXN" "$REPOS" "$i" | pmchecker || exit 1
done
ReadEncoding.pm [obsolete]

Perl module allowing the Apache web server to read the encoding of XML documents, in particular XHTML documents, and to generate the associated charset in the HTTP headers. Tested with Apache 1.3.26 to 1.3.29 and mod_perl 1.26 to 1.29 under Debian GNU/Linux.

To use this module, you need to modify the Apache configuration (in my case, the /etc/apache/httpd.conf file). If it has not been already done, you need to enable mod_perl by adding something like:

LoadModule perl_module /usr/lib/apache/1.3/mod_perl.so

With Debian, this is now configured with the apache package. Then, for the module itself:

<IfModule mod_perl.c>
  PerlTaintCheck On
  <Location />
    PerlFixupHandler ReadEncoding
  </Location>
</IfModule>

Thanks to Patrick for his invaluable help.

rpnews [no longer maintained]

Perl script to post news articles and retrieve the new ones with Suck, for the INN users. To use this script, you need to:

  • set the environment variable ISP_NNTPSERVER to the remote news server (new: or give the server as an argument);

  • change the values of some variables in the script (the values to use depend on your system);

  • set this script to setuid and setgid news.

Note: The current version has been written for the Debian GNU/Linux distribution and INN 2.3.2. Versions older than 2006-03-10 suffer from security problems (on multi-user machines).

ssh-forward

Shell script that sets up a tunnel from the local host A to a remote host B and rewrites the .ssh/config file on B to be able to access A from B. This is useful if, for instance, A is a laptop hosting some services via SSH. These services will be accessible via the same hostname, even if A moves from place to place (no need to modify Subversion's svn+ssh URL's and so on).

If $HOST is hostname.tld, the .ssh/config on B should have:

  Host hostname.tld
    HostKeyAlias hostname.tld
    Hostname anything
    Port any-number

Run the script on A with the following arguments: the name of the remote host (B) and the port number on B to use for the tunnel (any free port can be chosen). The Hostname and Port lines will be rewritten by the script.

sxw2txt

OpenOffice / OpenDocument text documents to plain text converter, based on Liam Morland's (see the source of this Perl script for the changes I've made). The generated text is encoded in UTF-8. Note that this converter is very basic; lots of features are still missing. To be able to use this program, you must have either the Archive::Zip Perl module or the unzip command.

Note: Though I mention this program on this page, it is not specific to Unices (but I haven't tested it on any other system).

This script is also distributed with Wolfgang Friebel's lesspipe.

tdiff

Perl script that processes diff output, in particular when it will be sent to a terminal: this utility can colorize it and convert it into UTF-8. I wrote it as a replacement for Dave Ewart's colordiff. In addition to UTF-8 conversion, the main advantage over colordiff (currently 1.0.10) is that tdiff starts to process the stream immediately (while colordiff first needs the stream to be closed).

tps

Perl script displaying the process list as a tree. This script uses the ps utility; options for tps start with character :, the other arguments being passed to ps. No help file (tps is an old script which should be rewritten), but you can look at the source and snapshots: snapshot 1, snapshot 2.

Zsh SSH Utilities

The purpose of these scripts is to type the passphrase only at the first SSH connection from the concerned machine. The passphrase will not be asked just after you log to this machine; so, if you do not use SSH for this session, you will not need to type your passphrase. The passphrase will be forgotten only when the last zsh login shell terminates.

Utilities for svn

Here are my utilities specifically written in relation to the Subversion client svn.

ext-diff

Zsh script to be used as an external diff command for svn diff. The purpose of this script is to transform binary files of some types (PDF, SQLite database, etc.) into text files so that they can be diff'ed. For this reason, the --force option for svn diff needs to be used, and typical usage is: svn diff --force --diff-cmd ext-diff other arguments.

svncdiff

Wrapper for svn diff using my ext-diff and tdiff utilities. One can also ask for n context lines with a -n option (see the source file for details).

The -w option provides word differences by using François Pinard's GNU wdiff utility (the cwdiff wrapper is recommended).

svneditor

Wrapper to the editor for the Subversion client svn, whose goal is to remove trailing whitespace and trailing newlines from log messages.

svnwrapper.zsh / old svnwrapper.sh

Wrapper to the svn command. You can use it with a shell alias, such as:

alias svn='svnwrapper'

The zsh version of the wrapper provides two features:

  • With Subversion 1.6 and below, avoid Broken pipe error messages when piping the svn output to some command (such as less). If your system is in a language other than English, you will need to change the detection of the error message in this script.

  • With Subversion 1.7 and above, do standard path resolution on arguments that look like real pathnames (the peg revision must be empty). Basically, if one of the path components (except the last one) is a symbolic link to some (non-root) directory of the working copy, the command will follow this link, contrary to the official command. This is what Subversion 1.6 and below did, but in an inconsistent way.

The older version provides only the first feature. It is written in POSIX shell, thus doesn't need zsh to be installed, but it does not display prompts due to the svn prompt bug. Moreover, for correct exit status, it assumes that the right part of a pipe is the parent process.

swdiff

Simple GNU wdiff wrapper to be used with the svn command (Subversion client), e.g.

svn diff --diff-cmd swdiff other-arguments

or with a shell alias:

alias swd='svn diff --diff-cmd swdiff'

Note: alternatively, svn diff output can be piped to wdiff -d, without needing this wrapper.

But see the other solutions.



webmaster@vinc17.org