Running commands over ssh

I would like to run commands from julia over ssh. I know how to do this in an ad hoc way:

Cmd(`ssh user@remote 'ls'`)

However I wonder is there a way to use the full power of julia command running over ssh?
That is I would like to do something like this:

cmd = ssh("user@remote",
    pipeline(Cmd(`ls`, dir="/some/path"), `wc -l`, stdout="SomeRemoteFile.txt")
)
run(cmd)
1 Like

Not exactly what you’re asking about, but if you’re up for using an IDE, there’s awesome functionality built into Juno. See here.

I don’t know the answer to your specific question :-/

If you have the same version of Julia installed on the remote machine (and in the same location), you could use the Distributed library to do this — just r = addprocs(["remote.server"]) and then @spawnat r[1] run(...).

1 Like

Thanks for the answers so far. I would prefer if julia is not needed at the remote machine or at least not a specific version of julia.

@jw3126 - Did you ever find a clean solution to running remote commands over ssh from within Julia (without a Julia dependency for the remote server)? Thanks.

No I did not.

Wouldn’t it be easiest to run an actual shell on the remote with e.g.

run(`ssh user@remote "/bin/bash -c 'ls /some/path | wc -l > file.txt'"`)

That might be the best option. It does however not allow to use julia abstractions like pipeline over ssh, right?

No, but those Julia abstractions are a subset of the functionality provided by most shells, so you could conceivably write a package that creates the proper Cmd from your Julia function calls.