I have tried to tar archive via ssh and i thought nothing is tricky for me in this task. But then i need to tar file from a path that include the most recent changed directory. To get this i am using such command:
cd "$(\ls -1dt ./*/ | head -n 1)"
The entire command looks like:
ssh root@$ip "cd /dir1/dir2/ && cd "$(\ls -1dt ./*/ | head -n 1)" && cd /dir3/ && tar -cpf - *.log" > $dir/out.tar
Unfortunately i get:
./Recent/: No such file or directory
I have tried to change \ls -1dt ./*/ | head -n 1
to \ls -1dt /*/ | head -n 1
Then i got:
cd: dir3/: No such file or directory
All of the directories in /dir1/dir2/, for which i am searching for most recently changed dir, contain dir3 directory, thats why previous error is imposible.
Also if i manually go to my remote machine via ssh and perform each command (diffirent cd, searching, tar) one by one, searching will work correctly without errors, but in my case i need the "whole string" command, because it is only a part of my entire automation script.
How to solve this?
Thanks