scp list of files using FOR LOOP in ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting scp list of files using FOR LOOP in ksh
# 1  
Old 12-02-2012
scp list of files using FOR LOOP in ksh

hi

i want to scp files from remote server B to my local server A...

and i have a file containing list of all files to be scped from remote server B

there is a passwordless connectivity set between remote server and my local server.

need a ksh script.. with a for loop that goes through the file and scp-s all the files
from remote server B to my local server.

kindly help.
# 2  
Old 12-02-2012
Code:
#!/bin/ksh
cd /home/dir/for/my/files
while read fname
do
    scp remote::${fname}  .
done < my_file_list.txt

This assumes that when you connect to scp, $fname will have gotten the full, correct name of the file on the remote from your list of files.
# 3  
Old 12-02-2012
Using SFTP to Get list of files from remote server to local server:-
Code:
#!/bin/ksh

awk ' BEGIN { print "cd /remote_dir/" } { print "get " $0 } ' file_list.txt > SFTP_Batch.cntrl  # Create SFTP batch file using file_list.txt
sftp -b SFTP_Batch.cntrl remote_user@remote_server.com						# Run STP batch file to GET files

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need Help in ksh Script to list files older than 365 days from specified directories

Requirement is to list the files older than 365 days from multiple directories and delete them and log the list of files which are deleted to a log file. so 1 script should only list files older than 365 days for each directory separately to a folder The other script should read these files... (7 Replies)
Discussion started by: prasadn
7 Replies

2. UNIX for Dummies Questions & Answers

Help with ksh script to list files, cp it to another UNIX server

Hi, I'm quite new to ksh scripting, can someone help me with this. Requirements: I need to create a script that list the files from a user input date range. e. g. format of file: *c1*log.2012-12-22-14-00* *c1*log.2012-12-22-14-00* *c1*log.2012-12-22-14-00*... (7 Replies)
Discussion started by: chococrunch6
7 Replies

3. UNIX for Advanced & Expert Users

Help with ksh script to list, then cp files from a user input date range

Hi, I'm quite new to ksh scripting, can someone help me with this. Requirements: I need to create a script that list the files from a user input date range. e. g. format of file: *c1*log.2012-12-22-14-00* *c1*log.2012-12-22-14-00* *c1*log.2012-12-22-14-00*... (1 Reply)
Discussion started by: chococrunch6
1 Replies

4. Shell Programming and Scripting

scp in for loop

Hi, I am trying to transfer between two servers using this command, but it is asking me for password for each file. Any ideas are appreciated for i in `ls`; do scp $i/*unix* user@server.com:/target/folder;done (3 Replies)
Discussion started by: jacobs.smith
3 Replies

5. Shell Programming and Scripting

Displaying list of backup files using for loop

Hi, I want to display list of last 10 backup files (with numbering) from the temporary file c:/tmp/tmp_list_bkp.txt Example : 1) backup_file1 2) backup_file2 3) backup_file3 ........ ........ I tried as below but not working. for file in c:/tmp/tmp_list_bkp.txt do echo... (3 Replies)
Discussion started by: milink
3 Replies

6. Shell Programming and Scripting

KSH: Opening Files based on a file list

I'd like to grep files for key words using korn shell, and compile the actual contents (not just file name) of those files that contain a combination of those grepped key words into one repository file for reference. However, I'm stuck at the combining part. Here's what I have thus far: egrep... (5 Replies)
Discussion started by: drumminfool91
5 Replies

7. Shell Programming and Scripting

Removing banners from scp calls (AIX/KSH)

Hello all! I am creating a script to synchronize key files on multiple servers in our environment. What I have works, but I am getting the banner for each of the servers in the output and it makes it difficult to quickly review when there are over a dozen servers in the array. I have tried a few... (4 Replies)
Discussion started by: cpare
4 Replies

8. UNIX for Dummies Questions & Answers

Newbye. Help with KSH. Loop in files and remove first line

Hi everybody. Firstly, sorry for doing such a basic questions, but i have never worked with linux shells and at this moment i am trully desperated :d. I have been checkin' another posts of this forum looking for different things for mixing them and get the solution to my problem, but i have not ... (2 Replies)
Discussion started by: bringer
2 Replies

9. Shell Programming and Scripting

scp list of files

Hi, I have to get the list of files from my remote server to my local machine. i tried using such as scp uname@server1:/path/to/dir file1 file2 ./ But i got only the file1 and its saying file2 not found eventhough its there in remote machine. can anyone please help how to get the listed... (1 Reply)
Discussion started by: nmahendran
1 Replies

10. Shell Programming and Scripting

ksh: How to get latest file from a list of files in a directory

Hi, I need to get the latest file from a list of files in a particular directory. Please could anyone help me out to get the file. Thank you, - Jay. (1 Reply)
Discussion started by: Jayathirtha
1 Replies
Login or Register to Ask a Question