Changeset 1213
- Timestamp:
- 10/16/09 03:17:43 (5 weeks ago)
- Files:
-
- 1 modified
-
bin/sshjour (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
bin/sshjour
r1211 r1213 1 1 #!/usr/bin/ruby 2 2 3 # Bonjour host + port; fallback host + port 3 4 host, port, alternative, altport = ARGV 4 5 host = host + '.local' 5 6 7 # Default to fallback 6 8 found, fport = alternative, altport 7 9 … … 9 11 IO.popen('-') do |pipe| 10 12 if pipe # parent 11 fork { sleep 1; Process.kill 'ALRM', pipe.pid rescue nil } # timeout 13 # Timeout if reading hangs 14 alarm = fork do 15 begin 16 sleep 1 17 Process.kill 'ALRM', pipe.pid 18 rescue Exception => e 19 # That's ok! 20 end 21 end 12 22 key = pipe.read 13 23 24 # No zombie 25 Process.kill('INT', alarm) 26 Process.wait(alarm) 27 28 # Did we succeed, or timeout, or what? 14 29 Process.wait(pipe.pid) 15 30 if $?.success? 31 # Is it the key we're looking for? 16 32 known = IO.readlines(ENV['HOME'] + '/.ssh/known_hosts') 17 33 found, fport = host, port if known.include?(key) 18 34 end 19 else 35 else # child 20 36 $stderr.close 21 37 exec 'ssh-keyscan', host … … 28 44 end 29 45 30 # puts found46 # Make ourself into a connection 31 47 exec('nc', found, fport || '22')
