Archive for July 16, 2009

Plant my key

4

Here’s a neat little script that I developed at “the oven place”. It “plants” my SSH key on a remote machine, so I can get in later without entering a password.

#!/bin/sh
user_at_machine=$1
# plant my SSH key on the target machine
cat $HOME/.ssh/id_rsa.pub | \
   ssh $user_at_machine \
      "if [ ! -d .ssh ] ; then mkdir -m 700 .ssh ; fi ; \
      cat >> .ssh/authorized_keys"

All of the action takes place in one single line (which I broke up here so it would wrap OK). It takes your public key from the machine you’re on, and it pipes it into an SSH session, which you’ll have to type your password into. On the remote machine, it creates a .ssh directory if it needs to, and then it appends your public key to an authorized_keys file.

The next time you log in to that remote machine, you will not need to enter your password.

Counting down with ‘pv’

0

Here’s a neat tool.

Ever start some long task, and wonder how much longer it has to go? There’s a small utility called pv (short for “pipe viewer”) that counts time and bytes through a pipe, and it shows a nice progress bar.

Here’s how I used it to watch a very large file being compressed (note the use of the most excellent lzma compression utility.

$ pv < winxp.vdi | lzma > winxp.vdi.lzma
1.79GB 0:21:50 [1.49MB/s] [===>          ] 10% ETA 3:11:02

Note that if I had used a different pipe notation, pv would not have been able to read the input file size, and therefore it could not make estimates of remaining time. So instead, it shows you the “Knight Rider” scanning eye for progress.

$ cat winxp.vdi | pv | lzma > winxp.vdi.lzma
5.48MB 0:00:04 [1.27MB/s] [  <=>         ]

Nice tool. Thanks, Andrew!

Go to Top