Linux


Little know seq (sequence) utility is a great way to loop on a range of numbers in Linux. It came in very handy today and will hopefully stick in my brain in the future.

for i in `seq 1 10`
do
..
done

I discovered a large gap in my bash kung fun today - I had no idea how to loop on lines of data in a file.

It turns out that “while data” pulls off this trick quite nicely:


while read myline
  do $myline
done < inputfile

I was sick of typing in username/password for each login (I’m currently working on XP, deploying to a Linux-only env), so I finally went through the pain of following the steps here and set up PuTTY/Peagant public key authentication.

It was a relatively painless setup process, but here are a couple of things to keep in mind when going through it:

  • PuTTY is a pain to update/navigate as you have to remember to load/save during each setting update
  • You can “pre-enter” your remote username by setting “username@hostname” as the hostname
  • authorized_keys file on the remote box should have a mask of 600
  • putty.exe -load “session_name” allows you to create PuTTY shorcuts for each of your connections

Register is running a great story about how Bill Joy created vi.

Apparently, vi commands are cryptic because they were optimized for Bill’s 1200 baud connection.

For additional entertainment, you can read Reddit’s discussion of the article here - complete with (always entertaining) emacs/vi mud-slinging.

Would you like to create a lively, “top”-like output from some of the monitoring commands in your toolbelt?

“watch” can be of help here, as it can poll your command every X seconds and render its output to full screen.

Try “watch -n1 date” for a demo.

NAME
watch - execute a program periodically, showing output fullscreen

SYNOPSIS
watch [-dhv] [-n ] [–differences[=cumulative]] [–help]
[–interval=] [–version]

I’m administering a mix of Red Hat and Debian boxes, so this tip from bschmitz comes in handy…

cat /proc/version

Simple thing to do…had to look it up…

kill -HUP `cat /var/run/sshd.pid`

I stumbled onto this while troubleshooting Putty disconnects on XP…gotta love FAQs w/ attitude.

A.7.12 When I cat a binary file, I get ‘PuTTYPuTTYPuTTY’ on my command line.

Don’t do that, then.

This is designed behaviour; when PuTTY receives the character Control-E from the remote server, it interprets it as a request to identify itself, and so it sends back the string ‘PuTTY’ as if that string had been entered at the keyboard. Control-E should only be sent by programs that are prepared to deal with the response. Writing a binary file to your terminal is likely to output many Control-E characters, and cause this behaviour. Don’t do it. It’s a bad plan.

Check out Jeremy Mates’ reallykill script if you need to effectively kill a processes with a preference for graceful shutdown.

Bookmarking this…since I’m having lock problems with BerkeleyDB…

$ svnadmin create –fs-type fsfs /path/to/new/repository
$ svnadmin dump /path/to/repository | svnadmin load /path/to/new/repository

UPDATE (12/26/2006): I ended up pulling the trigger on the BerkeleyDB->FSFS conversion as I was getting absolutely sick of running the “svnadmin recover” and “db_recover” scripts. Conversion was painless - here’s the “productionalized” list of steps I followed:

1. Shut down svnserve, Apache, and anything else that might be accessing the repository.
2. svnadmin dump /path/to/repository > dumpfile.txt
3. mv /path/to/repository /path/to/saved-old-repository
5. svnadmin create –fs-type fsfs /path/to/repository
6. svnadmin load /path/to/repository < dumpfile.txt
7. Copy over hook scripts, etc, from the old repository to the new one.
8. Restart svnserve, Apache, etc.

Useful tip by Todd Huss - test your cron scripts using the env -i somescript.sh command

To follow the Linus/Tanenbaum microkernal debate I needed to brush up on my microkernel knowledge. Enter Wikipedia.

A microkernel is a minimal form of computer operating system kernel providing a set of primitives, or system calls, to implement basic operating system services such as address space management, thread management, and inter-process communication. All other services, those normally provided by the kernel such as networking, are implemented in user-space programs referred to as servers.

UPDATE: One of the Slashdot users posted “the truth about microkernels“.