Shell script for copying files from 1 server to other


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script for copying files from 1 server to other
# 1  
Old 08-10-2010
Shell script for copying files from 1 server to other

Hi,

I just need a shell script that copies a list of files from a directory in a remote server to my current directory at local server

the remote server may contain the following list:
/root/pradeep/myfiles/default
/root/pradeep/myfiles/dir1
/root/pradeep/myfiles/dir2
...
/root/pradeep/myfiles/dir10

the following are the conditions:
1) the mandatory parameters to the script are <server name> < userid> < password>

if this is given it should copy all the file in a directory /root/pradeep/myfiles/default
to my local system

2) if the fourth option is mentioned, that should be any directory name in /root/pradeep/myfiles/
the script should copies all the files in that directory
to my current directory

thanking you in advance

---------- Post updated at 09:46 AM ---------- Previous update was at 09:39 AM ----------

Actually i used the following script...unfortunatley if-condiiton is not supported in the FTP script i used what to do??? plz help me
Code:
#!/bin/bash
##
##Script to load FILES


if [ $# -lt 3 -a $# -gt 4 ] ; then
echo "please enter the command properly"
echo " "
echo "Usage: <Script_name><server><user_name><password>[<version>]"
echo "example: sh pradeep.sh server1 root root123 10.2.1.5"
echo "try again"
exit -1

elif [ $# -eq 3 ] ; then
hostname=$1
username=$2
password=$3

ftp -n -i $hostname <<END_SCRIPT
quote USER $username
quote PASS $password
bin
cd /root/pradeep/myfiles/default
mget *.rpm
END_SCRIPT
elif [ $# -eq 4 ] ; then
hostname=$1
username=$2
password=$3


ftp -n -i $hostname <<END_SCRIPT
quote USER $username
quote PASS $password
bin

cd /root/pradeep/myfiles
ls -l | grep "$4" > /temp/available.$$

temps =`cat /temp/available.$$`

if [ " $temps " == "" ] ; then
cd /root/pradeep/myfiles/$4
mget *.rpm
else
echo "Sorry the required file doesnt exit's"
fi
END_SCRIPT

fi


Last edited by Scott; 08-10-2010 at 02:15 AM.. Reason: Please use code tags
# 2  
Old 08-10-2010
Do you enable SSH services between these two servers?

scp with keyless will simplify the process.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copying the files in to multiple location using shell script

Hi All, i'm trying to copy the 1.txt files (sample files) in to different path location using the below command. But it is not copying the files , when i tried for single location able to copy the file. can any one please assist here. Please find the below path :- /ckr_mkr1/licencekey... (2 Replies)
Discussion started by: venkat918
2 Replies

2. Shell Programming and Scripting

Shell script for connecting multiple servers and then copying 30 days old files

Shell script for connecting multiple servers and then copying 30 days old files from those server . HI , I have 6 multiple servers pla1,pla2,pla3,pla4,pla5,pla6 1. These six servers have common shared mount point /var/share 2. Running script from /var/share to connect these servers.I... (1 Reply)
Discussion started by: rcroyal88
1 Replies

3. 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

4. Shell Programming and Scripting

Need help in finding and copying list of files using bash shell script

Dear All, I have a situation where I want to copy some files of type .txt. These files are o/p from one program. Some of the files are named as fileName .txt instead of fileName.txt after fileName by mistake I have specified "space". Now I want to move these files as follows. mv fileName*... (13 Replies)
Discussion started by: linuxUser_
13 Replies

5. Shell Programming and Scripting

Help with copying files using shell script

I want to write a shell script to copy a list of files from one directory to another. And while copying it should change the first character of the filename to uppercase and others to lowercase.Below is what i have tried so far. for file in "$@" do if then ufile=`echo $file | sed... (5 Replies)
Discussion started by: vishal.desai
5 Replies

6. Shell Programming and Scripting

Files copying - [ Listed files alone. ] - Shell script

Hi All, I am doing this for svn patch making. I got the list of files to make the patch. I have the list in a file with path of all the files. To Do From Directory : /myproject/MainDir To Directory : /myproject/data List of files need to copy is in the file: /myproject/filesList.txt ... (4 Replies)
Discussion started by: linuxadmin
4 Replies

7. Shell Programming and Scripting

Shell Script to connect to another server and copying files

Hi Unix Gurus, I have a doubt reg file transfer. I have used the below script to connect to another server and find files having modified for the last 24 hours and have to move the file to another server. While i tried i am getting authentication failed, destination path not found issue. ... (2 Replies)
Discussion started by: incepted
2 Replies

8. Shell Programming and Scripting

script for Copying files from one server to another using scp

Hi Scripting experts, I am new to the unix scripting. Please help me out for solving the condition given below I am trying to develop a script for Copying files which are getting generated in server A to server B using scp. In serverA files are generating as for eg abc1.txt, abc2.txt,... (5 Replies)
Discussion started by: rohithji
5 Replies

9. Shell Programming and Scripting

writing script in UNIX for copying files in two server

can anyone help me in writing script in UNIX for copying files in two server from the third server after checking the files in the third server and if there is anything new in the third server automatically it should be added to the rest of the two servers and if same file is existing in the two... (4 Replies)
Discussion started by: REKHA09
4 Replies

10. Shell Programming and Scripting

copying files and Renaming them + shell script

Hi, I have a problem. I have some text files in a folder. The names can be like: emp.txt emp1.txt emp3.txt 32emp4.txt What i need is i have to copy all the files which have "emp" string in their filename to a different folder and those file names... (7 Replies)
Discussion started by: pathanjalireddy
7 Replies
Login or Register to Ask a Question