Solaris下用scp自动同步文件

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

#!/bin/bash

# Setting cdm path is used to store client softwarehost_dir=”/var/hostdir”# Statement the file is used to store the size of cdm folder sizefsrecord=”.r”# To synchronize the target machine ipclient_ip=”192.168.0.2″# To synchronize the target machine directoryclient_dir=”/var/clientdir”

# Current file folder sizenew_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” > $fsrecordfiold_folder_size=”$(cat $fsrecord|tr -d ‘M’)”# Remove character ‘M’temp_new=”$(echo $new_folder_size|tr -d ‘M’)”

# Compare file folder sizeif [ “$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 > $fsrecordelse echo “—–The folder has not been changed, so it does not need to synchronize.—–“fi

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

参考《ssh(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 cron

相信梦想是价值的源泉,相信眼光决定未来的一切,

Solaris下用scp自动同步文件

相关文章:

你感兴趣的文章:

标签云: