File transfer between two Linux servers

Source: Internet
Author: User
Tags scp file

There is a requirement in recent work that the files on a server need to be uploaded to the B server.

Originally want to use Java development, but think of Java development cycle long, to deal with such a small need not need to use Java, finally selected shell script, the relevant code is as follows:

1#!/bin/Bash2 3 functionError_exit {4Echo" $" 1>&25Exit16 }7 8#Local Directory (modifiable items)9Sourcepath=/opt/file One#remote server IP, port, directory (modifiable items) Atargetip=192.168.1.100 -targetport= A -Targetpath=/opt/file -#how often to scan a directory (modifiable items) -Sleeptime= - -  +  -  while true +  Do ANowtime= ' Date'+%y-%m-%d%h:%m:%s'` atEcho"$nowTime-start scan dir files ..." -curday= ' Date +%y%m%d ' -#Create a directory -Targetdatepath="$targetPath/$curday" -Ssh-p $targetPort $targetIp"[-D $targetDatePath]">/dev/null2>&1 -   if[ $? !=0 ] in    Then -Echo"$nowTime-auto Create remote dir $targetDatePath ..." toSsh-p $targetPort $targetIp"mkdir $targetDatePath"|| Error_exit"$nowTime-line Number: $LINENO, create remote dir failed, exit ..." + fi -    the    forFileinch$ (Find $sourcePath/$curday-name"*.xml") *    Do $Scp-p $targetPort $file $targetIp: $targetDatePath | | Error_exit"$nowTime-line Number: $LINENO, SCP file failed, exit ..."Panax Notoginseng      -RM-RF $file the  Done +Echo"$nowTime-end scan dir files ..." A Sleep $sleepTime theDone

Specifies the local directory, which is a series of subdirectories with the date format as the directory name, scanning out all the XML files in the date directory;

Transfer to the remote server, the remote directory if there is no corresponding date directory is created, there is not created, and 5 minutes (configurable) to scan the directory;

File transfer between two Linux servers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.