Category Archives: Unix

I needed a catagory for stuff that was general unix, and not nessessarily linux specific

color grep

Every once in awhile I come across a feature of a piece of software, generally, a small utility that I hadn’t known about and that shows immediate value.  Today Jon showed me the --color flag for GNU grep.  It uses color to highlight the term you were searching for in the line returned.  For example:

# grep –color=auto -i metadata todo.txt
Metadata Functions to Move:
   MetadataView…Make sure only our indexed items are passed up.

Its a very simple thing, but one of those that I’m surpised I haven’t been using.  I know have a shell aliases for that.  See the grep documentation for more information.

[Update 6/2: has a great article on GNU grep’s new features which talks about the color.  One that I’m particularly expected about is the ability to use Perl-style regular expressions.]

Concatenate PDFs

I often like to print out many web pages to read on the train.  To not waste paper I like to print them 2 up and double sided.  If the printer supports it, I also like to staple the pages.  On Linux, I use Firefox to print to postscript, then used a2ps to have the PS files combined, 2-uped, and short-side duplexed.  I’d then manually staple it, as there was no good way to tell the print center at work to staple it.  I’d use a command line similar to this:

a2ps -Eps -Afill -stumble

I tried this approach under OS X, but the problem is that the postscript that is generated on OS X is so detailed that it takes forever to process to print out, on the order of 2 minutes of processing per article.  Since PDF is the spooling format for printing in OS X (coming soon to linux) I thought I’d look to see if there was an easy way to concatinate PDF files so I could then have the regular printing interface (via Preview) handle the 2-up, double-sided, stapling goodness.

After much searching around I found this article and later this web page.  Combining a bit from both, I came up with following that works really well in my few days of testing.

texexec --pdf --paper=letter --pdfarrange --result all.pdf 1.pdf 2.pdf 3.pdf 4.pdf

It runs really quickly (especially in comparison to the a2ps method) and then I just open all.pdf and print from there.  It requires that you have teTeX installed.  On both Linux and OS X I had this installed as part of the prerequesets for docbook and doxygen.

Things we have relearned today

Regular backups are your friend. Also, if you can’t normally back something up (i.e. data in open ldap’s backend) do a regular dump and back that up.

rsync/unison/scp data off your co-loc to a local machine, and back it up again, just for good measure.

The new drive is the drive most likely to die first.

Losing /var really fucking sucks.

Recreating most of the information in ldap out of mail logs is cool, though.

Drinking doesn’t solve sysadmin nightmares, but it makes you feel good while you’re having the nightmare.

SSH files that can bite you in the ass

Today, I learned about the existence of ~/.ssh/rc and some of its side effects.

Today, Dave couldn’t figure out why he was unable to launch an X application from a machine we both use. We both started looking into it, and it looked like xauth wasn’t being called to update the .Xauthority file. We spent a good half hour or more looking around trying to figure out if it was a bug in OpenSSH on his mac, or one on the Linux server, if xauth was wonky, or what other small differences there were between his server side environment and mine.

During the search I found this post on a Debian mailing list. It was a red herring as it had us investigating a few dead ends. However, it did point out to my mind the existence of the ~/.ssh/rc file. Up until this point, I didn’t know of this files existence. Anyway, while looking in ~dave/.ssh/ I saw he had such a file.

To quote from the man page:

Commands in this file are executed by ssh when the user logs in
just before the user’s shell (or command) is started. See the
sshd(8) manual page for more information.

There was an emacs backup file (rc~) there, which I looked into. At one time Dave used it to set a umask for all his connections that came in via ssh. For whatever reason, he must have decided that was not doing what he wanted, so he removed the umask line, but didn’t remove the file. Because the file existed, ssh was trying to execute the commands in it, and since there was nothing in it, ssh did nothing and dumped him to a shell.

From the behavior of ssh, it appears there is a “default” rc that happens if you don’t have one or one doesn’t exist in /etc/ssh. One of the tasks of this default includes calling xauth if you’re doing X11 forwarding. By having an empty file there, Dave was bypassing all of it. I haven’t taken the time to see what other side effects came about from that, but there must not have been much, as Dave hadn’t noticed it since last April (at least according to the mod time on the rc file.)

Dave just IMed me and told me to look at the sshd man page and see the following:

When a user successfully logs in, sshd does the following:
8. If $HOME/.ssh/rc exists, runs it; else if /etc/ssh/sshrc
exists, runs it; otherwise runs xauth. The “rc” files are
given the X11 authentication protocol and cookie in standard

One other thing we learned in this is that xauth is dumb dumb stupid. xauth won’t create a .Xauthority file if there is nothing to put into it, such as when you call “xauth list” when a file doesn’t exist. However, if you do an “xauth list” and you don’t have a .Xauthority file, xauth spits out a diagnostic message saying its creating it. In reality, it doesn’t really create the file. Bad coding on someone’s part. This wasted us time, as we though it was xauth that was broken, not Dave’s ssh environment. One could argue that xauth IS broken by demonstrating this behavior, but that’s a different rant.