aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <m@maandree.se>2025-02-08 16:43:41 +0100
committerMattias Andrée <m@maandree.se>2025-02-08 16:43:41 +0100
commit521fbb5a8294f4ad924e10bcc871c95be12957ba (patch)
tree74923bb8092173a77082a2af0081014e2a89cc3f
parentUpdate README (diff)
downloadsshexec-521fbb5a8294f4ad924e10bcc871c95be12957ba.tar.gz
sshexec-521fbb5a8294f4ad924e10bcc871c95be12957ba.tar.bz2
sshexec-521fbb5a8294f4ad924e10bcc871c95be12957ba.tar.xz
Add cd option
Signed-off-by: Mattias Andrée <m@maandree.se>
-rw-r--r--README11
-rw-r--r--sshexec.115
-rw-r--r--sshexec.c14
3 files changed, 37 insertions, 3 deletions
diff --git a/README b/README
index 2029106..71bf2af 100644
--- a/README
+++ b/README
@@ -2,7 +2,7 @@ NAME
sshexec - run a command through ssh(1) with normal command syntax
SYNOPSIS
- sshexec [{ [ssh=ssh-command] [dir=directory]
+ sshexec [{ [ssh=ssh-command] [dir=directory] [cd=(strict|lax)]
[[fd]{>,>>,>|,<,<>}[&]=file] }] [ssh-option] ...
destination command [argument] ...
@@ -43,6 +43,15 @@ OPTIONS
In the remote, change working directory to directory
before executing command.
+ cd=strict
+ Fail without executing the command if it's not possible
+ to set directory as the remote working directory.
+
+ cd=lax
+ Continue (but warn) executing the command even if it's
+ not possible to set directory as the remote working
+ directory.
+
[fd]>=file
After changing working directory (assuming one is
specified), create or truncate the specified file and
diff --git a/sshexec.1 b/sshexec.1
index 91922f6..d18635d 100644
--- a/sshexec.1
+++ b/sshexec.1
@@ -8,6 +8,7 @@ sshexec - run a command through ssh(1) with normal command syntax
.RB [ {
.RI [\fBssh=\fP ssh-command ]
.RI [\fBdir=\fP directory ]
+.RB [ cd= ( strict | lax )]
.RB [[\fIfd\fP]{ > , >> , >| , < , <> }[ & ] = \fIfile\fP]
.BR } ]
.RI [ ssh-option ]\ ...\,
@@ -107,6 +108,20 @@ In the remote, change working directory to
before executing
.IR command .
.TP
+.B cd=strict
+Fail without executing the
+.I command
+if it's not possible to set
+.I directory
+as the remote working directory.
+.TP
+.B cd=lax
+Continue (but warn) executing the
+.I command
+even if it's not possible to set
+.I directory
+as the remote working directory.
+.TP
.IB \fR[\fPfd\fP]\fP >= file
After changing working directory (assuming one is specified),
create or truncate the specified
diff --git a/sshexec.c b/sshexec.c
index 67868ee..03810e8 100644
--- a/sshexec.c
+++ b/sshexec.c
@@ -19,7 +19,7 @@ static void
usage(void)
{
exitf("usage: %s [{ %s }] [ssh-option] ... destination command [argument] ...\n",
- argv0, "[ssh=command] [dir=directory] [[fd]{>,>>,>|,<>}[&]=file]");
+ argv0, "[ssh=command] [dir=directory] [cd=(strict|lax)] [[fd]{>,>>,>|,<>}[&]=file]");
}
@@ -129,6 +129,7 @@ main(int argc_unused, char *argv[])
{
const char *dir = NULL;
const char *ssh = NULL;
+ const char *cd = NULL;
struct redirection *redirections = NULL;
size_t nredirections = 0;
char *destination;
@@ -140,6 +141,7 @@ main(int argc_unused, char *argv[])
char opt;
const char **args;
size_t i;
+ int strict_cd;
(void) argc_unused;
@@ -158,6 +160,7 @@ main(int argc_unused, char *argv[])
for (; *argv && strcmp(*argv, "}"); argv++) {
STORE_OPT(&ssh, "ssh")
STORE_OPT(&dir, "dir")
+ STORE_OPT(&cd, "cd")
p = *argv;
while (isdigit(*p))
@@ -202,6 +205,13 @@ main(int argc_unused, char *argv[])
if (!ssh)
ssh = "ssh";
+ if (!cd || !strcmp(cd, "strict"))
+ strict_cd = 1;
+ else if (!strcmp(cd, "lax"))
+ strict_cd = 0;
+ else
+ usage();
+
opts = argv;
nopts = 0;
while (*argv) {
@@ -263,7 +273,7 @@ dest_dir_checked:
if (dir) {
build_command_asis("cd -- ");
build_command_escape(dir);
- build_command_asis(" && ");
+ build_command_asis(strict_cd ? " && " : " ; ");
}
build_command_asis("exec env --");
for (; *argv; argv++) {