日期:2014-05-16  浏览次数:20704 次

Linux远程文件拷贝

#!/bin/sh
 
 ################################################################################
 ######把10.0.64.224主机上/data/sea/upload/底下文件拷贝到10.10.31.79#############
 ######文件拷贝成功后,把文件从10.0.64.224主机上删除,本地记录操作日志#############
 ################################################################################
 
 
 #远程主机地址
 remote_ip=10.0.64.224;
 
 #远程主机登录用户
 remote_user=root;
 
 #远程主机目录
 remote_path="/data/sea/upload";
 
 #本地保存远程拷贝文件目录
 local_path="/usr/data/upload/ftpupload";
 
 #本地日志文件输出目录
 log_dir="/home/web_sea/logs";
 
 
 log_file_date=`date +%F`;
 
 for file in `ssh ${remote_ip} ls ${remote_path}`
 do
      scpfile="scp ${remote_user}@${remote_ip}:${remote_path}/${file} ${local_path}/";
      $scpfile;
      log_date=`date +%F" "%T`;
      if [ $? -eq 0 ] ; then
         echo "$log_date debug scp file [$file] is successfully" >> $log_dir/access_${log_file_date}.log
         ssh ${remote_ip} rm -rf ${remote_path}/${file}
         if [ $? -eq 0 ] ; then
             echo "$log_date debug delete file [$file] is successfully" >> $log_dir/access_${log_file_date}.log
         else
             echo "$log_date error delete file [$file] is failure" >> $log_dir/error_${log_file_date}.log
         fi
      else
         echo "$log_date error scp file [$file] is failure" >> $log_dir/error_${log_file_date}.log
      fi
 done
?