linux scp 同步文件夹,Solaris下用scp自动同步文件

1. scp同步文件脚本 //syntest.sh

#!/bin/bash

# Setting cdm path is used to store client software

host_dir="/var/hostdir"

# Statement the file is used to store the size of cdm folder size

fsrecord=".r"

# To synchronize the target machine ip

client_ip="192.168.0.2"

# To synchronize the target machine directory

client_dir="/var/clientdir"

# Current file folder size

new_folder_size="$(du -sh $host_dir |awk '{print $1}')"

# Read the size of the folder and remove character 'M'

if [ ! -f $fsrecord ]

then

echo "0M" > $fsrecord

fi

old_folder_size="$(cat $fsrecord|tr -d 'M')"

# Remove character 'M'

temp_new="$(echo $new_folder_size|tr -d 'M')"

# Compare file folder size

if [ "$temp_new" != "$old_folder_size" ]

then

scp -r $host_dir $client_ip:$client_dir

echo ""

echo "-----The folder has been synchronized success!-----"

# Write the latest file folder size

echo $new_folder_size > $fsrecord

else

echo "-----The folder has not been changed, so it does not need to synchronize.-----"

fi

2. 为scp自动拷贝生成不用输入密码的密匙

3. 用crontab定时运行脚本。

1.) 将syntest.sh拷贝到/etc目录下

2.) 编辑crontab,文件在/var/spool/cron/crontabs下

比如:每分钟运行一次

0-59 * * * * /etc/syntest.sh  //*/5    每5分钟1次  */20    每20分钟1次   在Linux下可以,但是在Solaris下不支持

4. refresh crontab

svcadm refresh cron0b1331709591d260c1c78e86d0c51c18.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值