I have an org-babel source, which accesses a server via tramp and runs a shell script there. Is it possible to convert this source block into an Elisp function?
#+BEGIN_SRC sh :dir "/pscp:putty-connection-xy:/dir-yz"
expect -c '
spawn bash -c "scp file-to-copy user@server:/home1/dir-xy"
expect {
"(yes/no)?" {
send "yes\r"
expect "*?assword:*"
send "secretPassWord\r"
}
"*?assword:*" {
send "secretPassWord\r"
}
}
expect eof
'
#+END_SRC
Use Tramp's multi-hop (untested):
(copy-file "/plink:putty-connection-xy:/dir-yz/file-to-copy"
"/plink:putty-connection-xy|ssh:user@server:/home1/dir-xy/")
This uses plink
and ssh
, 'tho. If you can connect user@server
directly from your local machine, you could shorten this, using pscp
:
(copy-file "/pscp:putty-connection-xy:/dir-yz/file-to-copy"
"/pscp:user@server:/home1/dir-xy/")
The solution is simple. I call the block and give it over 'sh', the code and the parameters of the block. It works
(org-babel-execute-src-block nil
'("sh"
"cd /home1/
expect -c '
spawn bash -c \"scp file-to-copy user@server:/home1/dir-xy .\"
expect {
\"*?assword:*\" {
send \"secretPassWord\\r\" } }
expect eof'
"
((:colname-names) (:rowname-names)
(:result-params "raw" "replace")
(:result-type . value) (:results . "silent")
(:exports . "code")
(:tangle . "no") (:hlines . "no") (:noweb . "no")
(:cache . "no") (:session . "none")) "" nil nil ))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.