Sponsored Content
Top Forums Shell Programming and Scripting Copy multiple .txt files from one server to another server Post 302955572 by Don Cragun on Friday 18th of September 2015 05:44:42 PM
Old 09-18-2015
Quote:
Originally Posted by karmegam
This is not a homework. This is the usual work that i use to perform every week so one of my friend suggested to automate the process to save time to spend on other works as am fully engaged. here is the one that i tried am not sure whether its correct or not i just gave a try as am very new to the shell programming and UNIX environment. This is just a part to get the files from source to target.

Code:
#!/bin/sh
HOST=source server(A)
echo "copying files from A server to B:/target/location"
'ftp -n $HOST >>END_SCRIPT
echo "connection success"
echo "logged on to A server"
cd /source/location
echo "source location log on success"
echo "starting the files transfer"
get A.txt
get B.txt
get C.txt
get D.txt
get E.txt
get F.txt
get G.txt
get H.txt
get I.txt
get J.txt
get K.txt
get L.txt
get M.txt
get N.txt
get O.txt
get P.txt
get Q.txt
get R.txt
echo "transfering of all 18 files done successfully"
bye
echo "Logged out of A server successfully"
END_SCRIPT'

EXIT_STATUS=$?
if[[ $EXIT_STATUS -eq 0 ]]
then
mailx -s\'"FTPing Files got failed"' kamegam@xxxx.com < $MSG/ftp_fail.msg
exit 1
else
mailx -s\'"FTPing Files are success"' kamegam@xxxx.com < $MSG/ftp_suc.msg
fi
exit 0

You seem to have a few problems:
  1. You can't mix ftp commands (e.g., get) and shell commands (e.g., echo) that way.
  2. Single quoting a command makes the shell think the entire single quoted string is the name of a command to execute.
  3. Iinstead of redirecting the output of the ftp command it looks like you want ftp to read the input from a here-document in your script.
  4. Using the ftp -n option tells ftp not to login to your destination host.
  5. Exit status 0 indicates success; not failure.
  6. You can't use a variable ([e.g., ICODE]$MSG[/ICODE]) before you assign a value to it. (Well, you can, but you'll get an empty string from the expansion.)
Assuming that you are logged into Server B when you run this code and that /bin/sh on your system is not a pure Bourne shell (which does not recognize [[ expression ]], maybe something more like:
Code:
#!/bin/sh
# Note that "HOST=source server(A)" only works if there are no space or ()s after the "=".
HOST="serverA"

echo "copying files from A server to B:/target/location"
ftp $HOST <<-END_SCRIPT
	verbose
	cd /source/location
	lcd /target/location
	mget [A-R].txt
	bye
END_SCRIPT
EXIT_STATUS=$?
echo "Logged out of A server with exit code $EXIT_STATUS"

if [[ $EXIT_STATUS -ne 0 ]]
then	mailx -s "FTPing Files got failed" kamegam@xxxx.com < /path/to/ftp_fail.msg
	exit 1
else	mailx -s "FTPing Files are success" kamegam@xxxx.com < /path/to/ftp_suc.msg
fi
exit 0

would work better, but this is completely untested.
 

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

copy files from remote server (B) to target server (A)?

Hi All, what is the comand to log off the remote server? I have 2 servers A, B. I need to find all files older than 7 days on server B and copy over to server A. My logic is: login the remote server: ================= ssh hostB cd /data/test find . -mtime -7 -ls | awk '{print... (4 Replies)
Discussion started by: Beginer0705
4 Replies

3. UNIX for Dummies Questions & Answers

Copy files from remote server

Hi Friends, Could you please help me as per my requirement mentioned below ? I have to copy files from one unix server to another unix server, and the files that i need to copy from the remote server are only those which are modified/created Today from abc directory on the remote server (1 Reply)
Discussion started by: ramask
1 Replies

4. Shell Programming and Scripting

Copy file from one server to multiple server

can some one help me to write a shell script that copy one file from one server to multiple server ex:suppose i wnt to copy file abc.txt which is in server 1 to server2,server3,server4....:confused: (6 Replies)
Discussion started by: alokjyotibal
6 Replies

5. UNIX for Advanced & Expert Users

Best way to Copy Files From One server to another server

Hi , I have two servers say server A and server B. I am generating some files in server A which I have to copy to Server B,what will be the best option and why it is better than the other( as I have to copy more than 3 GB data files daily) 1.FTP - I can't use FTP bcoz it's not allowed due to... (2 Replies)
Discussion started by: wangkc
2 Replies

6. Shell Programming and Scripting

Unix shell script to Copy files from one Windows server to another Windows server.

Can anybody please help me on how to code for the below requirement: I need to write a shell script (on different unix server) to copy files from multiple folders (ex. BRN-000001) from one windows server (\\boldls-mwe-dev4)to a different windows server(\\rrwin-ewhd04.ecomad.int). This shell... (4 Replies)
Discussion started by: SravsJaya
4 Replies

7. Shell Programming and Scripting

FTP multiple files from one server to one server

Hi, I'm new to shell script..I have one requriement like - In one server have more than one files,I want to ftp those files to some otehr server.. Ex : test1.pdf test2.pdf Please suggest me how to do (3 Replies)
Discussion started by: venkaswa
3 Replies

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

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

10. Shell Programming and Scripting

Shell script to copy a file from one server to anther server and execute the binary

Hi , Is there any script to copy a files (weblogic bianary + silent.xml ) from one server (linux) to another servers and then execute the copy file. We want to copy a file on multiple servers and run the installation. Thanks (1 Reply)
Discussion started by: Nawrajesh
1 Replies
All times are GMT -4. The time now is 12:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy