April 06, 2011
How many times a day do you see something like this?
$ ssh sam@drasticcode.com
sam@drasticcode.com's password:
Well f**k that. Typing in ssh passwords is for suckers. Personally I try to never do it, and to make it easier I have a pwdeath script to make setting up ssh keys painlessly easy. Once you’ve generated ssh keys (you can do this with ssh-keygen) put this script in your PATH.
#!/bin/bash
key=`cat ~/.ssh/id_rsa.pub`
for host in $*; do
ssh $host "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod 700 ~/.ssh && chmod -R 600 ~/.ssh/* && echo '$key' >> ~/.ssh/authorized_keys"
done
Then you invoke it like this:
$ pwdeath sam@server1.com sam@server2.com
Type your password once for each server, then never type it again. Your fingers will thank you.
Tagged with: bash |
June 25, 2010
The other night at nopoconi I drank a couple Super Dog IPAs and hacked together a tiny web application that will run the content of any two web pages through a diffing tool. It’s up on wiff.me.
In the process I also discovered this crazy bash command that will pipe two web requests as inputs through diff using subshells. It’s kind of an insane one-liner.
diff <(curl 'drasticcode.com') <(curl 'www.drasticcode.com')
Needless to say I punted on trying to use the one-liner in the web based version. Echoing user provided data to the shell scares me. @donpdonp taught me how to sanitize the user provided data in the bash command. Just replace any single quotes in the user provided urls with two single quotes. I still ended up using Sinatra and Curb.
Tagged with: bash |
September 08, 2009
One of the handiest tools in my programming toolkit is ack, a Perl script that is great for searching through code (or really any text files). I use it a lot while refactoring, for example when I want to rename a method every time it’s called in a project.
You can install
ack with this command (from
http://betterthangrep.com/):
$curl http://betterthangrep.com/ack-standalone > ~/bin/ack && chmod 0755 ~/bin/ack
Assuming that ~/bin/ack is in your path searching code is as easy as this:
$ ack my_poorly_named_method
Tagged with: bash |
August 01, 2009
Here’s a few tricks that I often use on the command line to save time. They take advantage of some variables that the bash shell uses to store various aspects of your history.
Repeating the last command with !!
Sometimes I run a command that requires sudo access, but forget the sudo. This is a great opportunity to use !! which holds the last command you ran.
$ tail /var/log/mail.log
tail: cannot open `/var/log/mail.log' for reading: Permission denied
$ sudo !!
sudo tail /var/log/mail.log
# output of command
Tagged with: bash |