LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-25-2020, 04:46 AM   #1
Sahib Sadman
LQ Newbie
 
Registered: Apr 2020
Posts: 2

Rep: Reputation: Disabled
SCP command for copying .txt files from one remote server to another remote server for last 10 days


I have two remote hosts.
host1-> 10.2.3.2
host2-> 10.3.0.2

I have 500 txt file in one remote server. I want to copy it to another remote server using SCP command for last 10 days. I have userID & access to both server.How can I do this?

Thanks
Sahib
 
Old 04-25-2020, 05:11 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
You compose one or several scp commands that will do what you want. That's really basic stuff. If it doesn't work, show us what you got.

I don't get the "last 10 days" bit though.
 
3 members found this post helpful.
Old 04-25-2020, 10:45 AM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,635

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Sahib Sadman View Post
I have two remote hosts.
host1-> 10.2.3.2
host2-> 10.3.0.2

I have 500 txt file in one remote server. I want to copy it to another remote server using SCP command for last 10 days. I have userID & access to both server.How can I do this?
Not really enough details, but between the find command and the scp command, it should be pretty easy. First thing I'd do is use ssh-copy-id to make sure whatever user ID you have can log in without a password, using a key swap. After that, you can run a command via command-line with SSH to find files created in the last ten days, and copy them via SCP.

Pretty simple to script, just need a while loop to process the ssh file list.
 
1 members found this post helpful.
Old 04-25-2020, 01:39 PM   #4
Sahib Sadman
LQ Newbie
 
Registered: Apr 2020
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ondoho View Post
You compose one or several scp commands that will do what you want. That's really basic stuff. If it doesn't work, show us what you got.

I don't get the "last 10 days" bit though.
I have tried with below command.
scp 'find /data1/client/apache-tomcat/icms_client/null/ -type f -name "*.txt" -mtime -10 -printf '%f\n'' user@10.2.3.2:/data1/client/apache-tomcat/icms_client/null

but it's not working.
 
Old 04-25-2020, 02:57 PM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,635

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Sahib Sadman View Post
I have tried with below command.
scp 'find /data1/client/apache-tomcat/icms_client/null/ -type f -name "*.txt" -mtime -10 -printf '%f\n'' user@10.2.3.2:/data1/client/apache-tomcat/icms_client/null

but it's not working.
That command doesn't look right...have you read the man page on the find command?? And what do you mean by "not working"??? What does that command do and return??
http://man7.org/linux/man-pages/man1/find.1.html

Not sure what you're doing with the printf or the \n in your command, since the find command will return the file name(s) by itself, and the options should come first.
Code:
scp `find -type f -iname *.txt -mtime -10 /data1/client/apache-tomcat/icms_client/null/` user@10.2.3.2:/data1/client/apache-tomcat/icms_client/null
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
scp : -l option (bandwidth limiting) doesn't work when scp-ing from a remote server to another remote server stoorky Linux - Server 10 03-05-2018 03:28 AM
drag-drop copying and cp command both hang at last few KB when copying to flash drive slacker_ Linux - Newbie 1 09-05-2013 07:17 AM
[SOLVED] awk question - read in txt files, offset data by given amount, output new txt files pomico Programming 19 09-17-2012 11:43 AM
Copy the contents of a txt file to other txt files (with similar names) by cp command Aquarius_Girl Linux - Newbie 7 07-03-2010 12:54 AM
cat onelinefile.txt >> newfile.txt; cat twofile.txt >> newfile.txt keep newline? tmcguinness Programming 4 02-12-2009 06:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration