Dirty sshfs hack: smount

I love SSHFS. I manage a lot of machines, and I very often want to do something like this:

diff root@server1:/etc/randomrcfile root@server2:/etc/randomrcfile

There are ways to do this with Kompare (a KDE diff app) and the fish:// Kioslave, but not on the command line. SSHFS makes it easy:

mkdir /tmp/server1 /tmp/server2
sshfs root@server1:/ /tmp/server1/
sshfs root@server2:/ /tmp/server2/
diff /tmp/server1/etc/randomrcfile /tmp/server2/etc/randomrcfile

I do this so often that I’ve written my own script to handle this for me, smount. Copy it somewhere in your path, remove the extension (or don’t, as you prefer), and optionally make a copy or symlink called “sumount”. Now you can rapidly mount and unmount multiple hosts.

List hosts:
smount

Mount two hosts:
smount server1 server2

Unmount all hosts:
smount -a

Help:
smount -h

Caution: this script is a dirty hack written in bash script. It assumes that it is free to create /tmp/hostname, and it doesn’t play well on a multi-user workstations (I don’t want to mount in /tmp/tyler@host or something like that). It also assumes that you have root access on your remote machines, so you probably want to use SSH keys.

smount works on Ubuntu hardy. However, I’ve found that the output of “mount” listings for FUSE filesystems changes from release to release. So don’t be surprised if “smount -a” stops working when you upgrade Ubuntu. I’ll try to keep an up-to-date copy here.

If you don’t know what you’re doing with mount or SSHFS, or if you’ve never totally destroyed a filesystem by accident (and are thus extremely cautious about doing it a second time), then DO NOT use this script. No warranty or fitness for purpose is implied. Your mileage may vary. RTFM.

Tags: , ,

  1. jb’s avatar

    ssh user@remote cat /path/to/file | diff -u – /path/to/other/file

    Reply

  2. tyler’s avatar

    That would work if the two machines can SSH to each other. In the case of my more secure servers, that is not true. But a good trick, thanks!

    Reply

  3. ®om’s avatar
    diff <(ssh server1 cat file) <(ssh server2 cat file)

    Reply

Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.