cancel
Showing results for 
Search instead for 
Did you mean: 

scp files by date only

SOLVED
Go to solution
NDO
Super Advisor

scp files by date only

Hi All

Please I have got a directory with files of january, feb, march, april etc, etc.

I only want scp files of january to another server.

Can somebody help?

F.R.
10 REPLIES
Stephan._1
Trusted Contributor
Solution

Re: scp files by date only

Hi,
a quick and dirty and not tested solution ...

for MYOBJ in $(ssh ""ll | awk '{ if ($6 == "Jan") print $9}'"")
do
scp -p ://${MYOBJ}
done

Replace
with you source server
...


hth
Stephan
Share what you know, learn what you don't.
NDO
Super Advisor

Re: scp files by date only

Hi

I did the following:
for JOB in `ls -lrt | awk '{if ($6 == "Jan")print $9}'`
do scp -p /tmp/fr/$JOB root@:/tmp/fr/pr03
done

But its prompt me for password for every file

Is it possible to get away with this password issue?

F.R.
Stephan._1
Trusted Contributor

Re: scp files by date only

You can use ssh-keygen to generate a ssh key without password, add the ssh key from the server you run the job in the authorized_keys file on the server you are copying from.

Best,
Stephan
Share what you know, learn what you don't.
NDO
Super Advisor

Re: scp files by date only

Hi!

Sorry Iam not following you, can you give me a step by step procedure?

F.R.
Stephan._1
Trusted Contributor

Re: scp files by date only

Source Server: A
Target Server: B

On B:
1. check ~/.ssh if a file id_dsa.pub or id_rsa.pub exist, if yes go to 3.
2. run 'ssh-keygen -t rsa' - do not enter a password, under ~/.ssh/ the file id_rsa.pub and id_rsa will be created
3. Copy the .pub file to A

On A:
4. go to ~/.ssh/
5. run 'cat .pub >> authorized_keys'

Next login should be without asking for a password.

Best,
Stephan
Share what you know, learn what you don't.
NDO
Super Advisor

Re: scp files by date only

Hi Stephen!

Thanks a lot its working fine, but after I open another session to transfer other files in the same manner I got the following error:

CDESPATMOZ0106102 100% |********************************************************************************************| 123 00:00
CDDOM01MOZ0101802 100% |********************************************************************************************| 22268 00:00
Segmentation Fault - core dumped


Any ideas?

F.R.
Stephan._1
Trusted Contributor

Re: scp files by date only

Probably the ls -ltr produce an output which cause that - as mentioned in the first post, it's a quick and dirty solution.

Check what the command will give you on your source server:
ls -lrt | awk '{if ($6 == "Jan")print $9}'

Or in the loop change the scp to a simple echo $OBJ to see what comes up.

Something with blanks, special chars, ... ?

hth
Stephan



Share what you know, learn what you don't.
NDO
Super Advisor

Re: scp files by date only

Hi, I am closing the thread, I beleive I previously got that segmentation error, because of some other issue with the server.

Thansk Stephen, I will now assign 10 points to you

F.R.
NDO
Super Advisor

Re: scp files by date only



I am reopen this thread:

I am trying to copy files from one server to the other. The problem is from source directory I only want to transfer files from Jan 2011, but there also files from Jan 2010. So I can scp only the files from Jan 2011?

Your help will be appreciated.




F.R.
NDO
Super Advisor

Re: scp files by date only

by