Creating a ksh script to copy a folder


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating a ksh script to copy a folder
# 1  
Old 05-23-2016
Creating a ksh script to copy a folder

Hi Folks,

I need help in creating a ksh script to copy a folder from one server to multiple other servers using ssh and sftp.

The thing is the folder name changes daily. So is there a way we could specify the folder name during the execution of script.?

I would appreciate a quicker help. Its sort of emergency!!

Thanks,
Lena
# 2  
Old 05-23-2016
What operating system are you using?

What version of the Korn shell are you using?

Exactly what command would you use to copy the source directory to one of the target servers?

Is the list of servers to which you want to copy files fixed? If so, where is the list? If not, how do you expect your script to know which servers are to be used?

What folder is to be copied? Is it a constant, or does it change every day?

Does your script need to ask the name of the target directory? Or, will you give your script the name of the target directory as a command line operand? Or, is the target directory name derivable from the current day's date?

Is the target directory the same path on each target server? Or, does each target server have a different target directory?

What have you tried to make this work on your own?
# 3  
Old 05-23-2016
Hi Don,

First of all thank you so much for you response.


Please find my answers inline

What operating system are you using?
[L]: unix

What version of the Korn shell are you using?
[L]: no idea

Exactly what command would you use to copy the source directory to one of the target servers?
[L]: Am thinkning of using scp for secure copying.

Is the list of servers to which you want to copy files fixed? If so, where is the list? If not, how do you expect your script to know which servers are to be used?
[L]: yes, the lists are fixed and i would save it as a conf file(EX. servername.conf), so that the target directory/path would be retrieved from the conf file.

What folder is to be copied? Is it a constant, or does it change every day?
[L]: It changes daily or as required.

Does your script need to ask the name of the target directory? Or, will you give your script the name of the target directory as a command line operand? Or, is the target directory name derivable from the current day's date?
[L]: target directory/path should be retrieved from the conf file.

Is the target directory the same path on each target server? Or, does each target server have a different target directory?
[L]: same path on all server

What have you tried to make this work on your own?
[L]: I am actually new to scripting. I use to copy the files with the help of winscp. Thought of automating the process to reduce time and scripting is the way i came up with.

A little help on how to make this owrk would be helpful.
# 4  
Old 05-23-2016
The easy way to write a script to do some is to figure out how to do it manually first and then build a script that incorporates that manual command (or set of commands) and puts it (or them) in a script with a little bit of boilerplate in a loop (since you want to repeat the process for a set of servers instead of just doing it for one server).

If you can't show us the exact command(s) you would type into ksh to copy files from your source folder to a destination folder on one of your target servers, and a sample of your configuration file format including at least the configuration details for the target server used in your example showing the commands you would use to manually copy files to that server, we can't help you automate your manual process.

Note that this is the UNIX and Linux Forums. My understanding is that winscp is intended for use on Windows systems; not UNIX and UNIX-like systems. When you need help with a script to run on Windows, you need to clearly state that up front. Are your destination servers also running Windows? (If not, what operating systems are they running.)

Note also that homework and coursework questions can only be posted in the Homework & Coursework forum under special homework rules. If this is a homework assignment, please review the guidelines for posting homework and repost in the proper forum.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to copy files from on folder to another

I am trying to copy files with specific date and name to another folder. I am very new to shell scripting so i am finding it hard to do that. see the sample code i have written below. srcdir="/media/ubuntu/CA52057F5205720D/Users/st4r8_000/Desktop/office work/26 nov"... (13 Replies)
Discussion started by: Aqeel Abbas
13 Replies

2. Shell Programming and Scripting

Shell script which will check the target file and folder exists and copy it

Hi All, I am a beginner in this and trying to write a shell script in linux which will : 1. Ask for a file name and check if its exists. 2. If file exists only then it will ask for the new target folder, after entering target folder name it will check if it exists. 3. If target folder... (3 Replies)
Discussion started by: ashish_neekhra
3 Replies

3. UNIX for Dummies Questions & Answers

UNIX ksh Copy Files Script

I need a UNIX ksh script that counts the number of files in directory, if the files exceed 20 files, then email results. I want the script to run every hour.. I don't have access to cron.. I'm some what new to UNIX. Windows guy all my career.. this is what I have so far.. #!/bin/ksh # count.sh ... (5 Replies)
Discussion started by: PerlHaven2k
5 Replies

4. Shell Programming and Scripting

Need help in writitng a script to rename file name and copy to other folder

Hi All, My requirement is as follows: A file (say abc) will be having list of the .txt file names. I need to read this abc file line by line and rename the .txt file names inside it and move them to other folder/path. Eg: abc ------- file1.txt file2.txt file3.txt Output (should... (1 Reply)
Discussion started by: pavan.yadalla
1 Replies

5. Shell Programming and Scripting

Script to create folder, copy file, and send email on success

I am very new to UNIX as well as scripting so please be gentle, haha. I have a Linux client which has a mount point mapped to my /etc folder on a NetApp FAS system. I woudl like to be able to copy the hosts and rc files once a week from the FAS to a different location for backup. When the... (4 Replies)
Discussion started by: minnino
4 Replies

6. Shell Programming and Scripting

how to execute ksh simple shell script without creating .sh file

please help me to execute a simple shell script like for i in `ls echo $i done . i dont want to create a new sh file to execute it. Can i just type and execute it ? because I always this kind of simple for loops . Please help . Thanks (7 Replies)
Discussion started by: Sooraj_Linux
7 Replies

7. Shell Programming and Scripting

How to unzip files from folder in shell script (ksh)?

I have a folder (C:\shellprg\input\) containing .CSV, .zip, .gz files. 1] I want to find all .zip/.gz files from folder (C:\shellprg\input\). 2] unzip/uncompress files into the same folder (C:\shellprg\input\) through shell script. I am using below commands for unzip files, unzip <filename>... (2 Replies)
Discussion started by: Poonamol
2 Replies

8. Shell Programming and Scripting

Copy a file by creating folder structure in destination as in Souce

Hello, i am having a source directory which consist of multiple sub directories and my destination folder is a empty directory. if try to copy a file source->test->1.txt from source to destination test2 using the commaind. cp source/test/1.txt desti/ It will copy the 1.txt under desti... (1 Reply)
Discussion started by: tsaravanan
1 Replies

9. Shell Programming and Scripting

Find all text files in folder and then copy to a new folder

Hi all, *I use Uwin and Cygwin emulator. I´m trying to search for all text files in the current folder (C/Files) and its sub folders using find -depth -name "*.txt" The above command worked for me, but now I would like to copy all found text files to a new folder (C/Files/Text) with ... (4 Replies)
Discussion started by: cgkmal
4 Replies

10. UNIX for Advanced & Expert Users

Auto copy for files from folder to folder upon instant writing

Hello all, I'm trying to accomplish that if a file gets written to folder /path/to/a/ it gets automatically copied into /path/to/b/ the moment its get written. I thought of writing a shell script and cron it that every X amount of minutes it copies these files over but this will not help me... (2 Replies)
Discussion started by: Bashar
2 Replies
Login or Register to Ask a Question