Linux+shell acquiring and copying the latest data to remote devices

Source: Internet
Author: User

Linux+shell acquiring and copying the latest data to remote devices

Our remote general copy of the data are created by the shared secret key, so that the copy of the words do not have to enter a password, specifically, I can refer to the previous article "Linux to realize the trust of SSH--http://gaowenlong.blog.51cto.com/451336/1856951 ”;

We will get the last modification time of the files in the Localbakdir directory through the script and remotely copy the latest modification time problem to Rmt_host

#!/bin/bashlocalbakdir=/oafs/weaver_backuprmtrestdir=/oafsrmt_host=192.168.6.38rmt_user=rootrmt_cmd= "$ (which  SSH)  [email protected] $RMT _host "#function  is_alive   determine if the remote computer is communicating properly function  Is_alive ()  {' which ping '  -c 4  $RMT _host >/dev/null 2>&1if [   "$?"  -ne 0 ]; thenecho 2elseecho 0fi}function mktmpdir ()  {$RMT _cmd  Mkdir -p /tmp/oafs}function rmvtmpdir ()  {$RMT _cmd rm -rf /tmp/oafs/*} Function get_last_targz ()  {echo $ (ls -lt  $LOCALBAKDIR  | awk {' Print  $9 '} |grep -v ^$ |head -n 1)}function copy ()  {yum install  -y openssh-clients >/dev/null 2>&1$RMT_CMD yum install -y  openssh-clients >/dev/null 2>&1scp -q  $LOCALBAKDIR/$ (get_last_targz)  [email  protected]$rmt_host:/tmp/oafs/}if [  "$ (is_alive)"  -eq 0 ];  thenmktmpdircopyrmvtmpdirelseecho  "$RMT _host can not be accessed via port  22, please check "fi

Finally, we use the script to obtain the file name under the Localbakdir directory to determine whether the latest file (the file name is named in the date format), the latest modification time problem is copied remotely to Rmt_host

#!/bin/bashlocalbakdir=/oafs/weaver_backuprmtrestdir=/oafsrmt_host=192.168.6.38rmt_user=rootrmt_cmd= "$ (which  SSH)  [email protected] $RMT _host "function is_alive ()  {' which ping '  -c  4  $RMT _host >/dev/null 2>&1if [  "$?"  -ne 0 ]; thenecho 2elseecho 0fi}function mktmpdir ()  {$RMT _cmd  Mkdir -p /tmp/oafs}function rmvtmpdir ()  {$RMT _cmd rm -rf /tmp/oafs/*} Function get_last_targz ()  {echo $ (ls  $LOCALBAKDIR  | awk  ' {match ($0,/.{ 4}-. {2}-. {2}/,a); B[a[0]]=$0;y=a[0]>y?a[0]:y}end{print b[y]} ')}function copy ()  {yum install  -y openssh-clients >/dev/null 2>&1$rmt_cmd yum install -y  openssh-clients >/dev/null 2>&1scp -q  $LOCALBAKDIR/$ (get_last_targz)  [email  protected] $RMT _host:/tmp/oafs/}if [  "$ (is_alive) " -eq 0 ]; thenmktmpdircopyrmvtmpdirelseecho " $RMT _host can not be  accessed via port 22, please check "fi


This article from "Gao Wenrong" blog, declined reprint!

Linux+shell acquiring and copying the latest data to remote devices

Related Article

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.