Command in the Shell

Asked

Viewed 47 times

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?

  • 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.

  • Fabricio. Yes.. running the command directly on the server makes the copy

  • @Create a script.sh with the code responsible for duplicate the file and execute the code ssh user@host 'bash -s' < script.sh

1 answer

1

The commands used are correct, but the use of quotation marks in the wrong place causes the error.

Follows:

ssh -oStrictHostKeyChecking=no user@IP "cd /home/user/backup_database/hour/ && cp `ls -1trap | grep -v '/$' | tail -n 1` ~/"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.