一个检测 show128 文件更新的 shell 脚本

由 徐永久 发表于 2003年09月30日 14:56。

证券公司的行情系统最重要的是 show128 库,这个库是上交所的行情。一般这个行情文件通过卫星发到证券公司的 Novell 行情服务器上。

Windows 客户端通过映射驱动器的办法取到这个库文件,我在 Windows 上安装 rsync 程序,侦听在 873 端口。在 Linux 上通过 rsync 脚本,不断去同步这个文件。

由于 crontab 的最小更新时间为一分钟,所以,rsync 的脚本采用死循环来实现。

获取 show128 的脚本如下:

while true
do
WEEK=`date +%w`
HOUR=`date +%k`
if [ $WEEK -ge 1 -a $WEEK -le 5 -a $HOUR -ge 8 -a $HOUR -le 16 ]
then
rsync -azv –exclude=”GZLX.*” hq::dbf .
fi
done

程序判断每周一到五,每天 8:00 到 16:00 才同步。

运行时,采用 nohup .. & 的方式实现。

同步后需要检测文件的更新情况,我的脚本是这样的:

#!/bin/bash
#检测 show128 的更新速度
count=0
total=0
echo begin:0 >show128_counts.txt
while true
do
p_time=`ls -l SHOW128.DBF –time-style=”+%H%M%S”|awk ‘{print $6}’`
# echo $p_time
sleep 9
c_time=`ls -l SHOW128.DBF –time-style=”+%H%M%S”|awk ‘{print $6}’`
diff=`expr $c_time – $p_time`
if [ $diff -gt 0 ]
then
count=`expr $count + 1`
if [ $diff -gt 40 ]
then
diff=`expr $diff – 40`
fi
total=`expr $total + $diff`
avg=`expr $total / $count`
echo $count:$c_time:[$diff s][avg:$avg s] >> show128_counts.txt
fi
done

脚本采用了 ls 命令的 +FORMAT 格式获取文件的秒。
并用 expr 得到两个时间之间的差,但是在两个时间属于不同分钟的时候,由于百进位和 60 进制的差别,需要减去 40 秒。

本脚本即计算出文件的平均更新时间。

相关文章

您可以 发表评论, 或者从您的网站trackback

发表评论

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image