2021/06/09
Cookbook: Running commands remotely
(I frequently write throw-away scripts in Gauche, and it occurred to me that they can be a nice source of cookbook recipe. I'll write them up as I come to useful snippets.)
With run-process
or do-process
,
you can invoke external commands (ref:gauche.process).
One of their interesting feature is that you can run the commands
on a remote host, if you have ssh access with public-key authentication
to it.
Just add :host
keyword argument.
(do-process '(ls) :host "remote.example.com") ;=> you see listing of your home directory at remote.example.com
Stdio is forwarded to the local process, so as process exit status.
The :directory
keyword argument works, though it is relative
to your home directory of the remote machine. So, you can mix
local execution and remote execution pretty much seamlessly.
The following snippet pushes local commits to the repo, pulls them
on the remote machine, rebuild and restart the service.
The return value of do-process
is a boolean indicating command
success or failure, so combining with and
is like
&&
in shell scripts.
(and (do-process '(git push) :directory *local-dir*) (do-process '(git pull) :host *host* :directory *remote-dir*) (do-process '(make) :host *host* :directory *remote-dir*) (do-process '(make restart) :host *host* :directory *remote-dir*))
Tags: Cookbook, gauche.process
Post a comment