定期拷贝最新文件到远程服务器

1.设置免密码scp

2.编写脚本:

#scp the lastest file to the dest path of server
#!/bin/bash
TIME_INTERVAL=60 #default 60s
function scp_the_latest_file_to_server()
{
    #get parameters
    server_ip=$1
    server_dest_path=$2
    local_file_path=$3
    #get the lastest file
    lastest_file=`ls -t $local_file_path | head -n 1`
    echo "the lastest file:"$lastest_file
    #get the system and file tiimestamp
    system_timestamp=$(date +%s)
    echo "system current timestamp:"$system_timestamp
    lastest_file_path=$local_file_path/$lastest_file
    echo "lastest file path:"$lastest_file_path
    lastest_file_timestamp=$(stat -c %Y $lastest_file_path)
    echo "lastest file current timestamp:"$lastest_file_timestamp
    #judge the time difference
    let difference=lastest_file_timestamp-system_timestamp
    if [ $difference -lt 0 ];then
        let difference=-difference
    fi
    echo "timestamp difference:"$difference
    if [ $difference -le $TIME_INTERVAL ];then
        scp $lastest_file_path $server_ip:$server_dest_path
        if [ $? -eq 0 ];then
            echo 'scp work ok.'
        fi
    fi
}
while true
do
    scp_the_latest_file_to_server 10.50.21.167 /home/ /home/wangbin/test
    sleep $TIME_INTERVAL
done

 

MD5校验码:f4f9ea3f7bcc3375192be61dc110cb58 1、本软件定时自动备份软件。 2、备份任务自动拷贝文件文件大小或修改时间变化的文件 3、MyCopy.exe是配置界面,该文件生成配置文件mycopy.ini,并能显示系统运行状态。 4、MyCopyTask.exe是执行拷贝任务的程序,它根据mycopy.ini配置的信息定时进行拷贝,在休眠状态下每5秒钟检查一次是否到达任务指定的拷贝时间。拷贝过程中出现错误,记录log.ini文件,但不会终止拷贝进程。 5、MyCopy.exe配置界面里有“启动”按钮把运行状态改为“运行”,并启动MyCopyTask.exe程序;“终止”按钮把运行状态改为“终止”,MyCopyTask.exe检测到系统状态时为“终止”则自动退出。“退出”按钮退出配置界面,但不会终止MyCopyTask.exe程序。“暂停”也会推出MyCopyTask.exe程序,但下次启动时,从上次暂停的任务开始继续拷贝。 6、MyCopyTask.exe运行时托盘上会显示图标。 7、要实现拷贝任务的自动启动,可以把MyCopyTask.exe加入到windows系统的“启动”菜单中,但配置文件中的运行状态一定是“启动”,否则程序会自动退出。 8、程序拷贝文件时意外终止,可以坚持mycopy.ini文件中的[系统状态]是否有“半个文件”,如果有说明“运行信息”中包含的文件没有拷贝完整。 9、如果因为某种原因错过了任务执行时机的话,拷贝程序会在启动后补回错过的拷贝任务。 10、任务名和文件路径中不能出现","(半角逗号) 11、标准版只记录log.ini文件,健康提示版当任务执行完之后会弹出提示信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值