Page 1 of 1

How to copy today's file to remote host .

Posted: Thu Aug 02, 2018 5:12 am
by sub320
I have a directory ( no sub directory ) , there are many files in it with differnet creation day , there are many files will be update to this directory on and on .

if I want to write a script so that today's file will be scp to another host , how to do it ?

I know the command "find" can search today file and output the result and run scp , is it a good method to use find or is there other better command may do that ?


#find . -mtime -1 -type f

Re: How to copy today's file to remote host .

Posted: Thu Aug 02, 2018 6:22 am
by coffee412
I would think using Rsync would be a good approach. It will sync directories for you.

Some further info and examples:

https://www.tecmint.com/rsync-local-rem ... -commands/

Re: How to copy today's file to remote host .

Posted: Thu Aug 02, 2018 8:49 am
by Mattyboy
Yeah +1 for rsync.

Code: Select all

rsync --help
Set up your script and add it to the crontab to automate the backup.

Code: Select all

crontab -e

Code: Select all

man crontab

Re: How to copy today's file to remote host .

Posted: Thu Aug 02, 2018 8:58 am
by WharfRat
rsync would be the better method, but if you want to go with find then find ~/script -type f -newermt "2018-08-02" -exec scp '{}' username@ip_address:~/script/ \; will do it :wink: