Created
December 4, 2009 12:04
-
-
Save hdorio/248994 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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