Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Clojure 以指定用户身份运行脚本_Clojure_Pallet - Fatal编程技术网

Clojure 以指定用户身份运行脚本

Clojure 以指定用户身份运行脚本,clojure,pallet,Clojure,Pallet,我试图在本地机器上以用户托盘的身份运行whoami,它似乎一直想以用户死鬼的身份运行 (ns localhost.idk (:require (pallet [compute :as compute] [api :as api] [actions :as actions]))) (def my-data-center (compute/instantiate-provider "node-list"

我试图在本地机器上以用户
托盘
的身份运行
whoami
,它似乎一直想以用户
死鬼的身份运行

(ns localhost.idk
  (:require (pallet [compute :as compute]
                    [api :as api]
                    [actions :as actions])))

(def my-data-center
  (compute/instantiate-provider
   "node-list"
   :node-list [["localhost" "whoami" "127.0.0.1" :ubuntu]]))

(def user-pallet
  (api/make-user "pallet"
                 :password "pallet"
                 :sudo-password nil
                 :public-key-path "/home/deadghost/.ssh/id_rsa.pub"
                 :private-key-path "/home/deadghost/.ssh/id_rsa"
                 :passphrase "my-ssh-passphrase-here"))

(pallet.api/lift
 (pallet.api/group-spec
  "whoami"
  :phases {:configure (api/plan-fn
                       (pallet.actions/exec-script
                        ("whoami")))})
 :compute my-data-center
 :user user-pallet)
提升的返回值
。输出为死鬼

{:initial-plan-state {:pallet.action/action-options {}},
 :environment
 {:compute #<NodeList pallet.compute.node_list.NodeList@b63e98>,
  :user
  {:username "pallet",
   :public-key-path "/home/deadghost/.ssh/id_rsa.pub",
   :private-key-path "/home/deadghost/.ssh/id_rsa",
   :public-key nil,
   :private-key nil,
   :passphrase "my-ssh-passphrase-here",
   :password "pallet",
   :sudo-password nil,
   :no-sudo nil,
   :sudo-user nil,
   :state-root nil,
   :state-group nil}},
 :results
 ({:target
   {:group-name :whoami,
    :default-phases [:configure],
    :phases
    {:pallet/os
     #<api$lift_STAR_$fn__14140 pallet.api$lift_STAR_$fn__14140@1db467f>,
     :configure
     #<idk$eval14723$fn__14725 localhost.idk$eval14723$fn__14725@baacb>},
    :group-names #{:whoami},
    :node
    {:name "localhost",
     :group-name "whoami",
     :ip "127.0.0.1",
     :os-family :ubuntu,
     :os-version nil,
     :id "localhost-127-0-0-1",
     :ssh-port 22,
     :private-ip nil,
     :is-64bit true,
     :running true,
     :service #<NodeList pallet.compute.node_list.NodeList@b63e98>,
     :hardware nil,
     :proxy nil,
     :image-user nil}},
   :target-type nil,
   :plan-state
   {:host
    {"localhost-127-0-0-1"
     {:pallet/os
      {nil
       {:context "os: ",
        :action-symbol clj-action13784,
        :id "Ubuntu",
        :release "14.04",
        :mach "i686",
        :rev "3.13.0-39-generic",
        :os "Linux",
        :os-family :ubuntu,
        :os-version "14.04"}}}},
    :pallet.action/action-options {}},
   :result
   ({:err "",
     :out "pallet:x:1001:1001:,,,:/home/pallet:/bin/bash\n",
     :exit 0,
     :flags #{},
     :flag-values {},
     :script
     "#!/usr/bin/env bash\nmkdir -p /home/deadghost || exit 1\ncd /home/deadghost\nset -h\nif getent passwd pallet; then :;else /usr/sbin/useradd pallet;fi\nexit $?",
     :action-symbol pallet.actions/user,
     :context nil}
    {:err "",
     :out "deadghost\n", <------------ OUTPUTS DEADGHOST INSTEAD OF PALLET
     :exit 0,
     :flags #{},
     :flag-values {},
     :script
     "#!/usr/bin/env bash\nmkdir -p /home/deadghost || exit 1\ncd /home/deadghost\nset -h\nwhoami\nexit $?",
     :action-symbol pallet.actions/exec-script*,
     :context nil}),
   :phase :configure}),
 :targets
 ({:group-name :whoami,
   :default-phases [:configure],
   :phases
   {:pallet/os
    #<api$lift_STAR_$fn__14140 pallet.api$lift_STAR_$fn__14140@1db467f>,
    :configure
    #<idk$eval14723$fn__14725 localhost.idk$eval14723$fn__14725@baacb>},
   :group-names #{:whoami},
   :node
   {:name "localhost",
    :group-name "whoami",
    :ip "127.0.0.1",
    :os-family :ubuntu,
    :os-version nil,
    :id "localhost-127-0-0-1",
    :ssh-port 22,
    :private-ip nil,
    :is-64bit true,
    :running true,
    :service #<NodeList pallet.compute.node_list.NodeList@b63e98>,
    :hardware nil,
    :proxy nil,
    :image-user nil}}),
 :plan-state
 {:node-values
  {nv14946
   {:err "",
    :out "pallet:x:1001:1001:,,,:/home/pallet:/bin/bash\n",
    :exit 0,
    :flags #{},
    :flag-values {},
    :script
    "#!/usr/bin/env bash\nmkdir -p /home/deadghost || exit 1\ncd /home/deadghost\nset -h\nif getent passwd pallet; then :;else /usr/sbin/useradd pallet;fi\nexit $?",
    :action-symbol pallet.actions/user,
    :context nil},
   nv14945
   {:err "",
    :out "deadghost\n",
    :exit 0,
    :flags #{},
    :flag-values {},
    :script
    "#!/usr/bin/env bash\nmkdir -p /home/deadghost || exit 1\ncd /home/deadghost\nset -h\nwhoami\nexit $?",
    :action-symbol pallet.actions/exec-script*,
    :context nil},
   nv14933
   {:id "Ubuntu",
    :release "14.04",
    :mach "i686",
    :rev "3.13.0-39-generic",
    :os "Linux",
    :os-family :ubuntu,
    :os-version "14.04",
    :action-symbol clj-action13784,
    :context "os: "},
   nv14932
   {:os-version "14.04",
    :os-family :ubuntu,
    :os "Linux",
    :rev "3.13.0-39-generic",
    :mach "i686",
    :release "14.04",
    :id "Ubuntu",
    :action-symbol clj-action13784,
    :context "os: "},
   nv14931
   {:release "14.04",
    :id "Ubuntu",
    :os-family :ubuntu,
    :os-version "14.04",
    :action-symbol clj-action13760,
    :context "os: infer-distro: "},
   nv14930
   {:err "",
    :out "{\n:id \"Ubuntu\"\n:release \"14.04\"\n}\n",
    :exit 0,
    :flags #{},
    :flag-values {},
    :script
    "#!/usr/bin/env bash\nmkdir -p /home/deadghost || exit 1\ncd /home/deadghost\nset -h\nif [ -e /etc/debconf_version ]; then\nID=$(cat /etc/redhat-release | egrep -o -e '^[A-Za-z ]+release' | sed -e 's/ release//')\nRELEASE=$(lsb_release -s -r)\nfi\nif [ -e /etc/lsb-release ]; then\nsource /etc/lsb-release\nID=${DISTRIB_ID}\nRELEASE=${DISTRIB_RELEASE}\nfi\nif [ -e /etc/redhat-release ]; then\nID=$(cat /etc/redhat-release | egrep -o -e '^[A-Za-z ]+release' | sed -e 's/ release//')\nRELEASE=$(cat /etc/redhat-release | sed -e 's/.*release//' | sed -e 's/[^0-9.]//g')\nfi\nif [ -e /etc/SUSE-release ]; then\nID=$(cat /etc/SUSE-release | tr ' ' | sed -e 's/VERSION.*//')\nRELEASE=$(cat /etc/SUSE-release | tr ' ' | sed -e 's/.*= //')\nfi\nif [ -e /etc/mandrake-release ]; then\nID=Mandrake\nRELEASE=$(cat /etc/mandrake-release | sed -e 's/.*release //' | sed -e 's/ .*//')\nfi\necho {\necho   :id '\"'${ID:-unknown}'\"'\necho   :release '\"'${RELEASE:-unknown}'\"'\necho }\n\nexit $?",
    :action-symbol pallet.actions/exec-script*,
    :context "os: infer-distro: "},
   nv14929
   {:mach "i686",
    :rev "3.13.0-39-generic",
    :os "Linux",
    :os-family :linux,
    :os-version "3.13.0-39-generic",
    :action-symbol clj-action13735,
    :context "os: infer-os: "},
   nv14928
   {:err "",
    :out
    "{\n:os \"Linux\"\n:rev \"3.13.0-39-generic\"\n:mach \"i686\"\n}\n",
    :exit 0,
    :flags #{},
    :flag-values {},
    :script
    "#!/usr/bin/env bash\nmkdir -p /home/deadghost || exit 1\ncd /home/deadghost\nset -h\necho {\necho   :os '\"'$(uname -s)'\"'\necho   :rev '\"'$(uname -r)'\"'\necho   :mach '\"'$(uname -m)'\"'\necho }\n\nexit $?",
    :action-symbol pallet.actions/exec-script*,
    :context "os: infer-os: "}},
  :host
  {"localhost-127-0-0-1"
   {:pallet/os
    {nil
     {:context "os: ",
      :action-symbol clj-action13784,
      :id "Ubuntu",
      :release "14.04",
      :mach "i686",
      :rev "3.13.0-39-generic",
      :os "Linux",
      :os-family :ubuntu,
      :os-version "14.04"}}}},
  :pallet.action/action-options {}}}

不确定,你的例子说明了什么,问题是什么

为什么要尝试从托盘用户(我说的是“(操作/用户(:用户名用户托盘)))创建用户? 请。删除以使您的问题更清楚

您的本地主机上是否存在托盘用户? 是苏多能吗

控制台的输出是什么? 用控制台输出,我的意思是

20:57:56.305 [operate-57] DEBUG pallet.ssh.execute - authentication {:sudo-user nil, :state-group nil, :private-key nil, :public-key nil, :sudo-password "*******", :private-key-path nil, :no-sudo false, :public-key-path nil, :passphrase nil, :username "initial", :state-root nil, :password "*******"}
20:57:56.305 [operate-57] DEBUG pallet.ssh.transport - SSH user initial :private-key-path null :private-key null :password *******
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15 ==>  -----------------------------------------
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15 ==> #!/usr/bin/env bash
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15 ==> set -h
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15 ==> echo {
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15 ==> echo   :os '"'$(uname -s)'"'
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15 ==> echo   :rev '"'$(uname -r)'"'
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15 ==> echo   :mach '"'$(uname -m)'"'
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15 ==> echo }
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15 ==> 
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15 ==> exit $?
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15 ==> ------------------------------------------
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15:22 send script via /tmp/palletxhoLT as root
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15   <== ----------------------------------------
20:57:56.409 [operate-57] DEBUG pallet.ssh.transport - send-text set mode /tmp/palletxhoLT 384
20:57:56.411 [operate-57] DEBUG pallet.script-builder - {}
20:57:56.411 [operate-57] DEBUG pallet.script-builder - prefix kw :sudo
20:57:56.412 [operate-57] DEBUG pallet.script-builder - prefix sudo {:sudo-user nil, :node-value-path nv20675, :state-group nil, :context ("os" "infer-os"), :private-key nil, :public-key nil, :sudo-password "test123", :private-key-path nil, :args ("echo {\necho   :os '\"'$(uname -s)'\"'\necho   :rev '\"'$(uname -r)'\"'\necho   :mach '\"'$(uname -m)'\"'\necho }\n"), :no-sudo false, :action {:action-symbol pallet.actions/exec-script*, :impls #<Atom@679f2b31: {:direct {:f #<exec_script$eval11637$exec_script_STAR__direct__11638 pallet.actions.direct.exec_script$eval11637$exec_script_STAR__direct__11638@705e0e14>, :metadata {:location :target, :action-type :script}}}>, :execution :in-sequence, :precedence {}}, :public-key-path nil, :passphrase nil, :username "initial", :state-root nil, :password "test123"}
20:57:56.412 [operate-57] DEBUG pallet.script-builder - sudo-cmd-for {:username "initial", :sudo-password "test123", :sudo-user nil, :password "test123", :no-sudo false}
20:57:56.412 [operate-57] DEBUG pallet.script-builder - prefix echo 'test123' | /usr/bin/sudo -S
20:57:56.412 [operate-57] DEBUG pallet.ssh.execute - ssh-script-on-target command {:env-cmd "/usr/bin/env", :env nil, :env-fwd [:SSH_AUTH_SOCK], :prefix ["echo" "'test123'" "|" "/usr/bin/sudo" "-S"], :execv ("/bin/bash" "/tmp/palletxhoLT")}
20:57:56.514 [operate-57] DEBUG pallet.execute - 192.168.35.15   <== [sudo] password for initial: {
20:57:56.514 [operate-57] DEBUG pallet.execute - 192.168.35.15   <== :os "Linux"
20:57:56.514 [operate-57] DEBUG pallet.execute - 192.168.35.15   <== :rev "3.5.0-23-generic"
20:57:56.514 [operate-57] DEBUG pallet.execute - 192.168.35.15   <== :mach "x86_64"
20:57:56.514 [operate-57] DEBUG pallet.execute - 192.168.35.15   <== }
20:57:56.616 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15   <== ----------------------------------------
20:57:56.616 [operate-57] DEBUG pallet.executors - default-executor
20:57:56.305[operate-57]DEBUG pallet.ssh.execute-authentication{:sudo user nil、:state group nil、:private key nil、:sudo password“**********”、:private key path nil、:no sudo false、:public key path nil、:passphrase nil、:username“initial”、:state root nil、:password“*******”}
20:57:56.305[operate-57]DEBUG plallet.ssh.transport-ssh用户初始:私钥路径null:私钥null:密码*******
20:57:56.407[operate-57]DEBUG pallet.ssh.execute-192.168.35.15==>-----------------------------------------
20:57:56.407[operate-57]DEBUG pallet.ssh.execute-192.168.35.15==>#/usr/bin/env bash
20:57:56.407[operate-57]DEBUG pallet.ssh.execute-192.168.35.15==>set-h
20:57:56.407[operate-57]DEBUG pallet.ssh.execute-192.168.35.15==>echo{
20:57:56.407[operate-57]DEBUG pallet.ssh.execute-192.168.35.15=>echo:os''$(uname-s)''
20:57:56.407[operate-57]DEBUG pallet.ssh.execute-192.168.35.15=>echo:rev'''(uname-r)''
20:57:56.407[operate-57]DEBUG pallet.ssh.execute-192.168.35.15=>echo:mach''$(uname-m)''
20:57:56.407[operate-57]DEBUG pallet.ssh.execute-192.168.35.15==>echo}
20:57:56.407[operate-57]DEBUG pallet.ssh.execute-192.168.35.15==>
20:57:56.407[operate-57]DEBUG pallet.ssh.execute-192.168.35.15==>exit$?
20:57:56.407[operate-57]DEBUG pallet.ssh.execute-192.168.35.15==>------------------------------------------
20:57:56.407[operate-57]DEBUG pallet.ssh.execute-192.168.35.15:22以root用户身份通过/tmp/palletxhoLT发送脚本

20:57:56.407[operate-57]DEBUG pallet.ssh.execute-192.168.35.15我只是想在本地机器上以用户
pallet
的身份运行
$whoami
。存在一个
托盘
用户,该用户具有密码
托盘
和无密码sudo设置。如果控制台输出是指脚本运行的结果
whoami
,那么它就是
deadghost
,可以在
lift
返回值中找到。1。我提到的操作将在您的目标上创建一个用户。我不确定是否能正确地将输出映射到whoami操作。您可以在我的答案中找到控制台输出示例。。。对我来说,这更清晰易懂。。。
20:57:56.305 [operate-57] DEBUG pallet.ssh.execute - authentication {:sudo-user nil, :state-group nil, :private-key nil, :public-key nil, :sudo-password "*******", :private-key-path nil, :no-sudo false, :public-key-path nil, :passphrase nil, :username "initial", :state-root nil, :password "*******"}
20:57:56.305 [operate-57] DEBUG pallet.ssh.transport - SSH user initial :private-key-path null :private-key null :password *******
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15 ==>  -----------------------------------------
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15 ==> #!/usr/bin/env bash
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15 ==> set -h
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15 ==> echo {
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15 ==> echo   :os '"'$(uname -s)'"'
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15 ==> echo   :rev '"'$(uname -r)'"'
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15 ==> echo   :mach '"'$(uname -m)'"'
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15 ==> echo }
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15 ==> 
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15 ==> exit $?
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15 ==> ------------------------------------------
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15:22 send script via /tmp/palletxhoLT as root
20:57:56.407 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15   <== ----------------------------------------
20:57:56.409 [operate-57] DEBUG pallet.ssh.transport - send-text set mode /tmp/palletxhoLT 384
20:57:56.411 [operate-57] DEBUG pallet.script-builder - {}
20:57:56.411 [operate-57] DEBUG pallet.script-builder - prefix kw :sudo
20:57:56.412 [operate-57] DEBUG pallet.script-builder - prefix sudo {:sudo-user nil, :node-value-path nv20675, :state-group nil, :context ("os" "infer-os"), :private-key nil, :public-key nil, :sudo-password "test123", :private-key-path nil, :args ("echo {\necho   :os '\"'$(uname -s)'\"'\necho   :rev '\"'$(uname -r)'\"'\necho   :mach '\"'$(uname -m)'\"'\necho }\n"), :no-sudo false, :action {:action-symbol pallet.actions/exec-script*, :impls #<Atom@679f2b31: {:direct {:f #<exec_script$eval11637$exec_script_STAR__direct__11638 pallet.actions.direct.exec_script$eval11637$exec_script_STAR__direct__11638@705e0e14>, :metadata {:location :target, :action-type :script}}}>, :execution :in-sequence, :precedence {}}, :public-key-path nil, :passphrase nil, :username "initial", :state-root nil, :password "test123"}
20:57:56.412 [operate-57] DEBUG pallet.script-builder - sudo-cmd-for {:username "initial", :sudo-password "test123", :sudo-user nil, :password "test123", :no-sudo false}
20:57:56.412 [operate-57] DEBUG pallet.script-builder - prefix echo 'test123' | /usr/bin/sudo -S
20:57:56.412 [operate-57] DEBUG pallet.ssh.execute - ssh-script-on-target command {:env-cmd "/usr/bin/env", :env nil, :env-fwd [:SSH_AUTH_SOCK], :prefix ["echo" "'test123'" "|" "/usr/bin/sudo" "-S"], :execv ("/bin/bash" "/tmp/palletxhoLT")}
20:57:56.514 [operate-57] DEBUG pallet.execute - 192.168.35.15   <== [sudo] password for initial: {
20:57:56.514 [operate-57] DEBUG pallet.execute - 192.168.35.15   <== :os "Linux"
20:57:56.514 [operate-57] DEBUG pallet.execute - 192.168.35.15   <== :rev "3.5.0-23-generic"
20:57:56.514 [operate-57] DEBUG pallet.execute - 192.168.35.15   <== :mach "x86_64"
20:57:56.514 [operate-57] DEBUG pallet.execute - 192.168.35.15   <== }
20:57:56.616 [operate-57] DEBUG pallet.ssh.execute - 192.168.35.15   <== ----------------------------------------
20:57:56.616 [operate-57] DEBUG pallet.executors - default-executor