Using shebang and lein-exec to write Clojure scripts that can use dependencies

A brief demonstration of how to run Clojure programs like scripts with leiningen.

#!/home/callen/bin/lein exec
(use '[leiningen.exec :only (deps)])
(deps '[[clj-ssh "0.5.5"]])
(use 'clj-ssh.ssh)

(println "Hello!")

(let [agent (ssh-agent {})]
  (add-identity agent {:private-key-path "/user/.ssh/id_rsa"})
  (let [session (session agent "localhost" {:strict-host-key-checking :no})]
    (with-connection session
      (let [result (ssh session {:in "ssh root@hostname ls" :agent-forwarding true})]
        (println (result :out))))))
lein exec my-script.clj

I know this site is a bit of a disaster zone, but if you like my writing or think you could learn something useful from me, please take a look at the Haskell book I've been writing. There's a free sample available too!