executable_ssh-keyscan.scm 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env -S guile --no-auto-compile -e main -s
  2. !#
  3. ;; ssh-keyscan.scm example1.org example2org
  4. (use-modules (ice-9 format)
  5. (ice-9 match)
  6. (ice-9 popen)
  7. (ice-9 rdelim)
  8. (json)
  9. (srfi srfi-1))
  10. (define (main . args)
  11. (match (first args)
  12. ((command args ...)
  13. (for-each (lambda (host)
  14. (let ((var host))
  15. ((@@ (ice-9 pretty-print) pretty-print) var)
  16. var))
  17. (apply append
  18. (map (lambda (arg)
  19. (let* ((port (open-pipe* OPEN_READ "ssh-keyscan" arg))
  20. (output (read-string port)))
  21. (close-port port)
  22. (map (lambda (host)
  23. (match (string-split host #\space)
  24. ((host public-key-type public-key)
  25. `(plain-file ,host
  26. ,(string-join (list host public-key-type public-key))))))
  27. (string-split (string-trim-right output #\newline)
  28. #\newline))))
  29. args))))))