Cool shell tricks are in the Shell Stuff portion of this site. Actual sysadmin tips and tricks are kept here. Mmmm... Unix....

Make your crappy PC keyboard a Unix keyboard!

Terminal (non-X)

Put this file /etc/rc.d/keydump.

Add this line to the end of /etc/rc.d/rc.local:

/bin/loadkeys < /etc/rc.d/keydump

Restart your computer, and you've got a Unix keyboard!

Of course, this only works for terminal, non-X stuff. X stuff is next.

X

NOTES/CAVEATS:
  1. For some reason, this makes gvim type every second greater-than or less-than keystroke as a space (starting with the first one --- very confusing!), and every even greater-than or less-thank keystroke as the expected char. Odd...
  2. This example is for Fedora Core 6. Your mileage may vary.

First, deal with the fact that xkb, xorg's low-level and apparently buggy (and in need of replacement) keyboard mapper, needs to be told that the backspace key is modifiable by the shift key the ctrl and alt keys.

Open the file /usr/share/X11/xkb/symbols/pc and change this

    key <BKSP> {
        type="CTRL+ALT",
        symbols[Group1]= [ BackSpace,   Terminate_Server ]
    };

to this:

    key <BKSP> {
        type="TWO_LEVEL",
        symbols[Group1]= [ BackSpace,   Terminate_Server ]
    };

Now, in your home directory, create a file called .xmodmaprc with the following lines:

! Swap Caps_Lock and Control_L
remove Lock = Caps_Lock
remove Control = Control_L
keysym Control_L = Caps_Lock
keysym Caps_Lock = Control_L
add Lock = Caps_Lock
add Control = Control_L

! Swap escape and backtick/tilde
keycode  49 = Escape
keycode   9 = grave asciitilde

! Swap backspace and backslash/bar
keycode  51 = BackSpace
keycode  22 = backslash bar

When you restart X, you will probably be asked to add .xmodmaprc; do so.

You now have a unix keyboard layout! Yay!

Easily manage environment variables for new/removed software packages

First, keep any custom-compiled or custom-loaded software packages in /usr/local: Red Hat and Fedora's package managers never install stuff in /usr/local, and never harm stuff that you have installed in /usr/local. /usr/local is assumed to be software packages "local" to your machine. (And, in case you have to reformat and re-install Red Hat or Fedora, you did make /usr/local its own partition, didn't you?)

Second, keep standalone software packages with their own bin/ and lib/ directories in their own directories off /usr/local. So, when you install Adobe's Acrobat, for instance, it is disirable to have the binary in /usr/local/Acrobat5/bin/acroread; do not copy it to /usr/local/bin/acroread. Or, for any jdk you get from sun, get the self-unzipping archive and also leave the directory structure in /usr/local, leaving the binaries in /usr/local/j2sdk1.4.2_07/bin, not /usr/local/bin. This way, it's easy to remove any software package from /usr/local: rm -rf /usr/local/Acrobat5 is all you need.

Of course, now you've got the problem of having to add /usr/local/Acrobat5/bin and /usr/local/j2sdk1.4.2_07/bin to every user's PATH, a potential administration nightmare! Well, remember, you are on Unix, an operating system that was designed by programmers and not marketers and focus groups, so there's actually quite an elegant solution to this problem.

What you want to do is add the following loop to the end of /etc/profile, which every sh and bash user sources on login:

# Added by System Administrator, 23 June 2004
for f in /usr/local/*/add_to_env.sh ; do
    if [ -r "$f" ]; then
        . $f
    fi
done

unset f

Now, you create a file named /usr/local/Acrobat5/add_to_env.sh with the following lines:

PATH=$PATH:/usr/local/Acrobat5/bin
export PATH

Or, for java, you can create /usr/local/j2sdk1.4.2_07/add_to_env.sh:

JAVA_HOME=/usr/local/j2sdk1.4.2_07
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH

As Brini Maxwell would say: "Now why didn't you think of that?" ;-)

Duplicating hard drives on shut down

Variant one: two hard drives always plugged in

Fedora Core has a shutdown feature where the last thing to get executed, after unmounting the file systems, is /sbin/halt.local, which you can make yourself.

Buy two hard drives of the same make and model, and create this /sbin/halt.local script:

#!/bin/sh

if [ -f /etc/dup_sda_on_shutdown ]; then
    echo "duplicating /dev/sda --> /dev/sdb"
    dd if=/dev/sda of=/dev/sdb
fi

For this script to work, you need to touch a file called /etc/dup_sda_on_shutdown. To disable the script, either remove the file, or rename it to /etc/dup_sda_on_shutdown_off.

Note that duplicating a hard drive takes a LONG time.

Variant two: second hard drive available as external USB or eSATA

Buy two hard drives of the same make and model, and create this /sbin/halt.local script:

#!/bin/sh

if [ -b /dev/sdb ]; then
    echo "duplicating /dev/sda --> /dev/sdb"
    dd if=/dev/sda of=/dev/sdb
fi

For this script to work, you need to have your external drive plugged it. For it to not work, you just need to have your external drive unplugged.