Posts tagged shell hackery
HOWTO install etherpad on ubuntu 9.10
Mar 2nd
Etherpad was opensourced by google, and has some generic installation instructions. Here’s the translation for Ubuntu Karmic Koala (release 9.10):
How to Convert Your Book’s Images to Kindle
Nov 7th
Taking your painstakingly typeset book and shoving it through the kindle “conversion” meatgrinder was an exercise in wincing. Most of the images were corrupted, there was whitespace sprinkled randomly throughout the copy, and it was a general mess.
Kindle supports direct upload of an html version of your book, but there’s a lot of finessing you need to do before it all goes smoothly. One of the tasks you’ll need to do is convert your book’s images to greyscale, and reduce their size to something Kindle-friendly. There are free tools to help you do this if you aren’t afraid of the terminal.
Using Mac OS X 10.5’s keychain for ssh
Jul 26th
The version of ssh that comes with Mac OS X 10.5.6 has a -K option that stores your passphrases in your system’s keychain.
Run this:
ssh-add -K [path to private keyfile]
Provide your passphrase once when asked, and keychain will provide the passphrase for you automatically. You should probably enable “Require password to wake this computer from sleep or screen saver” in the Security pane of the System Preferences if you decide to do this.
If you see
$ ssh-add -K ssh-add: illegal option -- K
it’s because you’re using the macports (or fink) version of ssh. (run ‘which ssh’ to find out). With macports, uninstall the “openssh” package:
sudo port uninstall openssh
The ‘-K’ option was discovered courtesy of http://www-uxsup.csx.cam.ac.uk/~aia21/osx/leopard-ssh.html.
http://kimmo.suominen.com/docs/ssh/ has some excellent ssh documentation.
Make “ps -ef” work in a shell on Mac OS X
Sep 10th
If you’re used to SunOS or BSD, you’ll be at home with Mac OS X’s “ps -aux” to get a process list from a shell prompt.
If you’ve been using any other recent unix, though, your fingers will want to type ps -ef instead. Rather than hack an alias to wrap ps to make this happen, it turns out there’s an easy way to return to the ps promised lands.
By default on Mac OS X 10.5.2, the shell environment’s COMMAND_MODE is set to legacy. If you set it to unix2003, you’ll get your ps -ef. Just add
export COMMAND_MODE=unix2003 alias zcat='gunzip -c'
to your ~/.bashrc to make it be set automatically.
The alias of zcat to gunzip -c fixes a “feature” in unix2003 mode — it removes gzip support from zcat. If you’re used to using zcat for both compressed .Z files as well as gzipped .gz files, you want the alias line as a workaround.
Preventing an external hard drive from idling on ubuntu
Jun 9th
I got a Seagate FreeAgent Pro external hard drive for backups (JWZ has a very straightforward article about this). It happily reformatted to ext3, and I kicked off an rsync of /home.
Because rsync figures out what files need copying before it copies them, and there are hundreds of thousands of files in my /home, there was more than a couple minutes of grinding on the local hard drive building a list of files to copy over. While this happened, the external drive idled into a “sleep” mode that ubuntu can’t seem to awaken it from.
This was slashdotted with an sdparm hack, but I believe this solution is better. Copy this new udev rule into /etc/udev/rules.d/50-local.rules (this is a new file that you will be creating):
# Seagate FreeAgent allow_restart fix (i/o errors)
SUBSYSTEMS=="scsi",DRIVERS=="sd",ATTRS{vendor}=="Seagate*",ATTRS{model}=="FreeAgent*",RUN+="/bin/sh -c 'echo 1 > /sys/class/scsi_disk/%k/allow_restart'"
Dealing with a directory with ~∞ files
Apr 23rd
Got a directory with > 10K of files? Need to move them up one directory? mv will fail you:
$ mv * .. -bash: /bin/mv: Argument list too long
The solution is to list the files one line at a time (with find or ls -1) and feed that to xargs:
ls -1 | head -100 | xargs -I f mv f ..
This moves the first 100 files up one directory.
Note that this won’t work if you’ve got whitespace in your filenames. Use find -0 and xargs -0 to null-separate your filenames in that case.
Verifying file integrity with debsums
Apr 21st
After upgrading my Ubuntu server, some security applications grumped about changed contents of some common binaries.
Just to be safe, I wanted to verify them explicitly with debsums, but debsums looks for package names, not paths to binaries. Here’s a script that validates chattr, find, perl, and lsattr–the “-s” option to debsums is “silent”, so no news is good news:
for i in /usr/bin/chattr /usr/bin/find /usr/bin/perl /usr/bin/lsattr ; do echo $i debsums -as $(dpkg -S $i | cut -d':' -f1 | sort -u) done
Running a command for all files whose name matches…
Apr 20th
I found a stray image named “img_1234.jpg” on a laptop and wanted to see if I already had it on my server.
On my Mac I could use spotlight’s nifty “kind:image” filter along with quicklook. Macworld has a great article about advanced spotlight usage.
On Ubuntu, it’s almost as easy:
locate -i img_1234.jpg | xargs -d'\n' feh -F -d
- The
locate -isays “find img_1234.jpg without case sensitivity. Locate likes to separate filenames (that might have spaces) with a newline. - The
xargs -d'\n'says “expect filenames that are are separated by newline - The
feh -F -dtells feh, a great little image viewer, to reduce the image to fit to the screen and draw the filename.
Recursive sort-by-modification-time
Oct 4th
This certainly isn’t rocket science, but it also is certainly not something you want to type more than once.
find . -type f -printf '%T@\t%p\n' | sort -n | cut -f2
And an application using feh:
find . -type f -printf '%T@\t%p\n' | sort -n | cut -f2 | xargs feh -F
And if you want the newest-written-to .log files, searching from the current working directory:
find . -name \*.log -type f -printf '%T@\t%p\n' | sort -rn | cut -f2 | head -30 | xargs -n 1 ls -lh