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?
Create a New Directory ( mkdir ) The first step in creating a new directory is to navigate to the directory that you would like to be the parent directory to this new directory using cd . Then, use the command mkdir followed by the name you would like to give the new directory (e.g. mkdir directory-name ).
Create a new directory on your server using the mkdir command. mkdir foldername – create a new directory called foldername. mkdir -p foldername – create a new directory called foldername, even if the directory already exists.
The last argument of ssh
is command you want to execute on the remote host:
TESTDIR="$HOSTNAME"
ssh [email protected] "mkdir -p ~/$TESTDIR/test"
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With