Created
April 7, 2009 16:39
-
-
Save dakrone/91322 to your computer and use it in GitHub Desktop.
This file contains 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
; The execution macro | |
(defmacro exec | |
"Execute a command on the shell, passing to the given function | |
the lazy sequence of lines read as output, and the rest of arguments." | |
[cmd pred & args] | |
`(with-open [br# (BufferedReader. (InputStreamReader. (.getInputStream (.exec (Runtime/getRuntime) ~cmd))))] | |
(~pred (line-seq br#) ~@args))) | |
; This works | |
(defn get-groups | |
"Given a hostname, get a list of groups on that Avamar server" | |
[host] | |
(exec (str "get_groups.sh " host) | |
#(doseq [line %1] | |
(println line)))) | |
; This works also | |
(defn get-clients | |
"Given a hostname and group, get a list of clients for the group" | |
[host group] | |
(exec (str "get_clients.sh " host " " group) | |
#(doseq [line %1] | |
(println line)))) | |
; This doesn't work | |
(defn drill-down | |
"Try to do both, Fail." | |
[hostname] | |
(exec (str "get_groups.sh " hostname) | |
#(doseq [group %1] | |
(exec (str "get_clients.sh " hostname " " group) | |
#(doseq [client %1] | |
(println "Group/client:" group client)))))) | |
; Fixed: | |
(defn drill-down | |
"Try to do both, Win." | |
[hostname] | |
(exec (str "get_groups.sh " hostname) | |
(fn [groups] | |
(doseq [group groups] | |
(exec (str "get_clients.sh " hostname " " group) | |
(fn [clients] | |
(doseq [client clients] | |
(println "Group/client:" group client)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment