mkdir -p over SSH bash
23,202
Solution 1
The last argument of ssh
is command you want to execute on the remote host:
TESTDIR="$HOSTNAME"
ssh [email protected] "mkdir -p ~/$TESTDIR/test"
Solution 2
If you have a pem file to ssh as authentication use the following
ssh -i your-key.pem user@ip_addr "mkdir -p /your_dir_name/test"
Comments
-
eekfonky almost 2 years
I have a small test script as follows;
TESTDIR="$HOSTNAME" ssh [email protected] "\$TESTDIR" mkdir -p ~/$TESTDIR/test exit
the output with
bash -x
is;+ TESTDIR=ndx + ssh [email protected] '$TESTDIR' + mkdir -p /home/user/ndx/test + exit
Yet on the remote server, no directory exists?