灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:1678回复:0

Linux远程文件拷贝

楼主#
更多 发布于:2012-12-20 16:00
Linux远程文件拷贝



Shell代码    

#!/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

喜欢0 评分0
游客

返回顶部