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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting KSH fetching files from server A onto server B and putting on server C
# 1  
Old 10-14-2012
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.

Last edited by BrownBob; 10-14-2012 at 08:14 AM..
# 2  
Old 10-14-2012
First try to read about scp , rsync , find with mtime and ssh
This User Gave Thanks to pamu For This Post:
# 3  
Old 10-14-2012
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?
# 4  
Old 10-14-2012
That's why i have given find and mtime

get the 30 day old files.
Code:
find /path/ -type f -mtime +30

Or check for date format
Code:
$ date +%Y%m%d
20121014

For avoid password promoting check for expect.
# 5  
Old 10-14-2012
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:
Code:
mkdir /home/brownbob/.ssh
chmod 600  /home/brownbob/.ssh

Your home directory cannot be other writable - has to be 755 or 750.
This User Gave Thanks to jim mcnamara For This Post:
# 6  
Old 10-14-2012
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 ----------

Quote:
Originally Posted by pamu
That's why i have given find and mtime

get the 30 day old files.
Code:
find /path/ -type f -mtime +30

Or check for date format
Code:
$ date +%Y%m%d
20121014

For avoid password promoting check for expect.

what is type f? Could you please help me with that..
# 7  
Old 10-14-2012
Quote:
Originally Posted by BrownBob

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?
20121001000009_224625.in for these files use..

ls 20121001* It will show files started with 20121001.

and for 30 days old file use

Code:
find /path/ -type f -mtime +30

Output is files, which are 30 days old. You can use this to scpSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Do I require remote login access to a windows server to transfer files from a UNIX server

Hi All I need to transfer a file from a UNIX server to a windows server. I saw that it is possible to do this using scp command by looking at the forum listed below: ... (2 Replies)
Discussion started by: vx04
2 Replies

2. Shell Programming and Scripting

Copying the files to Windows server from UNIX server

Hi Team, I had a requirement to write a shell script which automatically transfer the files from unix server to windows server. I can able to unix to unix using Scp command. I am not sure how to do unix to windows. I am very new on this concept. Could you please help me or guide in... (4 Replies)
Discussion started by: gvkumar25
4 Replies

3. Solaris

FTP-ing files from Windows server to UNIX server

I need to transfer files from a Windows server to the Unix server and have to run some shell script on it to get the required output. Is it possible to transfer files from Windows server to unix server through any shell script? If so can you please help me with the details. Thanks in... (8 Replies)
Discussion started by: ssk250
8 Replies

4. Solaris

Script to get files from remote server to local server through sftp without prompting for password

Hi, I am trying to automate the process of fetching files from remote server to local server through sftp. I have the username and password for the remote solaris server. But I need to give password manually everytime i run the script. Can anyone help me in automating the script such that it... (3 Replies)
Discussion started by: ssk250
3 Replies

5. UNIX for Dummies Questions & Answers

Transfer file from server B to server C and running the script on server A

I have 3 servers A, B, C and server B is having some files in /u01/soa/ directory, these files i want to copy to server C, and i want to run the script from server A. Script(Server A) --> Files at Server B (Source server) --> Copy the files to Server C(Target Server). We dont have RSA key... (4 Replies)
Discussion started by: kiran_j
4 Replies

6. Shell Programming and Scripting

Copy files from Linux server to Windows server

Hi All, I am generating report in a Linux server and once the report is generated the report(.txt file) needs to be automatically saved in a Windows servers. So i am looking for a script to transfer the file automatically from Linux server to Windows server? Please advise. Thanks... (3 Replies)
Discussion started by: arunmanas
3 Replies

7. Shell Programming and Scripting

Copy folder and files from unix server to linux server

We would be migrating unix solaries to Linux redhat. Basically source is unix and target is linux. i would like to copy entire file system unix/source/* to target linux/souce/* but target linux has only folder setup so what ever files copied need to be placed in the linux server with same... (8 Replies)
Discussion started by: balajikalai
8 Replies

8. Shell Programming and Scripting

script for to take files from FTP server to UNIX server and Unzipped that files

script for to take files from FTP server to UNIX server and Unzipped that files (1 Reply)
Discussion started by: sunilamarnadh
1 Replies

9. Shell Programming and Scripting

FTPing files from unix server to windows server

Hi, Below is the script which ftps the file from unix server and putting in a different directory(but on unix server) How can i ftp the files from unix server and to place in a secure location on windows server? what changes needs to be done to the below script? How can this be... (1 Reply)
Discussion started by: venkatesht
1 Replies

10. Shell Programming and Scripting

FTP multiple files from remote server to local server

Hi, I am facing a weired problem in my FTP script. I want to transfer multiple files from remote server to local server everyday, using mget * in my script. I also, want to send an email for successful or failed FTP. My script works for file transfer, but it don't send any mail. There is... (2 Replies)
Discussion started by: berlin_germany
2 Replies
Login or Register to Ask a Question