Unix stuff

SimpleCA

It's a simple app in TCL/TK to manage the basic functions of a Certification Authority (Enterprise Root CA). The sources can be downloaded from the author's site.

To make it work with recent Unices running TCL >= 8.4 one needs to replace the combobox.tcl file included in the package with a newer version, downloadable from http://www1.clearlight.com/~oakley/tcl/combobox/.

Update: now the surce is available via SVN at http://zarathustra.be/WebSVN, and maybe it includes the right combobox.tcl. — Andrea Paolini 2006/01/04 14:12

Mailman

Command line options to look into mailman mailing lists.

To search the mailing list to which email.addr is subscribed, use:

  find_member <email.addr>

To list all the existing mailing lists use:

  list_lists

To get the addresses subscribed to the ML listname use:

  list_members <listname>

To know the list administrators:

  list_admins <listname>
  list_admins -a

The shortest fork bomb

In bash or tcsh:

  : () { : | : &};:

Qmail LDAP

A short reminder on how to install QmailLDAP on Debian: see qmailldap.

FIXME probably outdated

A better "ps auxww | grep"

To quickly find all the processes matching a pattern you can define an alias like:

alias jj='ps auxww | grep'

The side effect of this alias is that it often also matches the grep process. A better solution is to define a function like:

jj () {
  TAIL=${1#?}
  HEAD=${1%$TAIL}
  ps auxww | egrep $HEAD{1}$TAIL
}

The function is POSIX-compliant and works in bash and zsh.

Bridging in Linux

Let's say the interfaces you want to use for bridging are eth0 and eth2.

First of all remove the IP address from eth0 (if you have one) and activate all the needed interfaces:

ifconfig eth0 0.0.0.0
ifconfig eth0 up
ifconfig eth2 up

Now create the bridge, and connect to it the interfaces:

 brctl addbr br0
 brctl addif br0 eth0
 brctl addif br0 eth2
 ifconfig br0 up

Check that's everything OK, using

brctl show
brctl showmacs br0
dmesg

If you need IP connectivity for the bridge host assign an IP to br0:

dhclient br0

To remove the bridge, do:

brctl delif br0 eth0
brctl delif br0 eth2
ifconfig br0 down
brctl delbr br0

Managing files with spaces

If you have to work in the shell with a list of files with spaces in their names, coming from stdin, you can't (easily) use the «for f in *.blah ; do SOMETHING ; done» idiom. The quickest solution is to use the read(1) command:

ls | while read f
  do echo FOO $f
done

If using find and GNU tools, you can try something along the lines of:

find . -type f -name "*.blah" -print0 | xargs -0 -L1 echo FOO

When processing script parameters, use $@ (between double quotes) instead of $*:

for f in "$@"; do

Checksum with openssl

  • SHA1: openssl sha1 <filename>
  • MD5: openssl md5 <filename>

Java Swing bug w/ Compiz

There's a bug in Java Swing libraries (at least in 1.5) that, when using a composite window manager (like Compiz), makes some or all window empty (i.e. with the content of the window not drawn).

You can try to work around this defining an enviroment variable:

export AWT_TOOLKIT="MToolkit"

Find unlinked open files

With lsof, sorted by size:

lsof +L1  | sort -n -k 7
lsof +L1  | awk '{print $1,$3,$7,$10,$11}' | sort -n -k 3 | uniq

Memory map of a process

To show the memory map of a process (Linux, Solaris):

pmap -x PID

Posix ACLs

In Linux, Solaris you use getfacl(1) and setfacl(1).

For Mac Os X there are specific options for chmod(1).

Debugging a shell script

With set -x at the start of the script you enable the printing of the command as they are executed. Disable with set +x.

Surviving ksh (AIX / HP-UX)

stty intr ^C erase ^? kill ^U # HP-UX
set -o emacs
alias __A=$(print '\0020') # ^P = up = previous command
alias __B=$(print '\0016') # ^N = down = next command

In-place editing

perl -i.bak -pe 's/foo/bar/g' *.txt
ruby -i.bak -pe '$_.gsub!(/foo/,"bar")' *.txt
ruby -i.bak -pe '$_.gsub!(%r{/usr/},"/usr/local/")' *.txt # Without slashes
# Replace DOS EOLs in all *sh
find . -name \*.sh -exec perl -i -pe 's/\r\n/\n/g' {} \;

Join lines starting with a RE

ruby -npe 'chomp! ; print "\n" unless $_.match(/^THISISMYREGEXP/); END {puts}'

Kill child processes on exit

#!/bin/bash
 
function killer()
{
  kill `jobs -p`
}
 
trap killer TERM INT
 
blah &
foo &
quux &
 
wait

rsync reminder

Remember that a trailing / in the source means “copy the content of this dir”

Linux

rsync --rsh=ssh --archive --verbose --acls --xattrs --one-file-system \
  --dry-run \
  --delete \
  /foo ap@host:/bar

…that's the same as:

rsync -e ssh -avAXxn --delete /foo ap@host:/bar

Mac Os X

rsync --rsh=ssh --archive --verbose --extended-attributes --one-file-system \
  --dry-run \
  --delete \
  /foo ap@host:/bar

Command history

To add command history and editing (readline-style) to commands (like wlst or sqlplus) you can use rlwrap as a wrapper.

rlwrap sqlplus

Bulk applying a sed command file

If for example you have a sed command file named placeholders.sed and you want to apply it to all the *sql files, you can run:

find . -name \*sql -exec sed -i -f placeholders.sed {} \;

For a search and replace, the sed command file could be something like:

s/&BIC_COUN/BR/g
s/&LOG_LEVE/6/g

Set operations from shell

cat a b | sort | uniq      # a union b
cat a b | sort | uniq -d   # a intersect b
cat a b b | sort | uniq -u # set difference a - b (lines in a not in b)

Find the full execution path for a script

DIR="$( cd "$( dirname "$0" )" && pwd )"
unix/unix.txt · Last modified: 2011/09/30 11:35 by ap
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki