KSH fetching files from server A onto server B and putting on server C

Dear Friends,

Sorry for this basic request. But I just started learning Ksh recently and still I am a newbie in this field.

Q: I have files on one server and the date format is 20121001000009_224625.in which has year (yyyy) month (mm) and date (dd). I have these files on server A. The task which I am trying to accomplish is: I need to fetch these files onto server B dated 30 days older, bzip them and put them on server C. This script would run as a cronjob in server B. All servers are sun solaris.

Could anybody please help me with the code on serverB? Any help would be greatly appreciated.

First try to read about scp , rsync , find with mtime and ssh

1 Like

Currently I use scp to manually transfer the files onto server B from server A use bzip to compress them on server B and then again use scp to transfer them to server C(creating respective folders - eg. 201210 for oct 2012). But how can I include the conditions to check for name automatically (30 days old). how can i use scp as it prompts for passwords to be entered manually. Could you guide me accordingly please?

That's why i have given find and mtime

get the 30 day old files.

find /path/ -type f -mtime +30 

Or check for date format

$ date +%Y%m%d
20121014

For avoid password promoting check for expect .

You need to have ssh-keys for passwordless ssh (scp, sftp, ssh).

ssh-keygen: password-less SSH login

Basically what you do is:
create ssh-keys on server A, on server B, and on server C.
then put keys on whatever node you want to connect to.

So If I want to connect FROM A to C, I first have to put my "A" keys over on "C".
keys live in authorized_keys in a special directory under your login directory:

mkdir /home/brownbob/.ssh
chmod 600  /home/brownbob/.ssh

Your home directory cannot be other writable - has to be 755 or 750.

1 Like

I have already set up the authorized users in the servers. Thanks to jim_macnamara.

How do i compare the file names to todays date? the format of the file name is 20121001000009_224625.in ..

and implement this in a if statement.. if the filename is < 30days prior to todays date scp the file to server B?

---------- Post updated at 06:14 PM ---------- Previous update was at 05:28 PM ----------

what is type f? Could you please help me with that..

20121001000009_224625.in for these files use..

ls 20121001* It will show files started with 20121001.

and for 30 days old file use

find /path/ -type f -mtime +30

Output is files, which are 30 days old. You can use this to scp:)

I am sorry if I put this wrongly.. but is the output going to give files older than 30 days or 30 days old? I am looking for older than 30 days.... Really sorry for mis-communicating.

For example: i will have files with 20121011.....dat 20120912....dat and many such months.

I want to just scp the files which are older than 30 days and scp them.

Yes it gives files older than 30 days.

for your above given formats do one thing.

for month sept and old.
Use
ls 201209* for sept.
ls 201208* for aug.