Skip to content

Instantly share code, notes, and snippets.

@hdorio
Created December 4, 2009 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hdorio/248994 to your computer and use it in GitHub Desktop.
Save hdorio/248994 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Send commands by ssh on remote host for a sshfs mounted directory
#
# Install : rename this 'sshdo' (I suggest in /usr/bin/)
# Usage : $sshdo command
# Credits : python version by cbenz see it at http://cbenz.pointique.org/post/2009/09/18/Travailler-avec-sshfs
# Author: Hadrien Dorio <hadrien.dorio at gmail.com>
if ARGV.size < 1
puts 'please enter a command'; exit 1
end
command = ARGV.join ' '
mount = `mount`.split "\n"
mount_line = mount.find{|item| item =~ / on #{Dir.pwd} type fuse.sshfs/}
begin puts 'mount not found, are you in the right directory?'; exit 2 end if mount_line.nil?
remote_hostname = mount_line.scan(/[^:]*/).first
begin puts 'hostname not found'; exit 3 end if mount_line.nil?
remote_path = mount_line.scan(/:(.*) on/)
begin puts 'remote path not found'; exit 4 end if mount_line.nil?
puts `ssh #{remote_hostname} "cd #{remote_path}; #{command}"`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment