1
I need to copy the last file created in one directory to another via ssh
.
I’m using the following command:
ssh -oStrictHostKeyChecking=no user@IP "cd /home/user/backup_database/hour/; cp "`ls -1trap | grep -v '/$' | tail -n 1`" ~/"
The command returns the following error when running the script:
cp: cannot stat 'shutdown.sh': No such file or directory
If you can help me with command or some other solution.
This regex matches the filename you want to copy?
– Fabricio
It is not working because when you use the bass accents, it performs the listing on the right where the code was executed and not on the server side.
– Valdeir Psr
Fabricio. Yes.. running the command directly on the server makes the copy
– andré
@Create a
script.sh
with the code responsible for duplicate the file and execute the codessh user@host 'bash -s' < script.sh
– Valdeir Psr