首页 > 科技 > cp_cmp testing script and net state monitor

cp_cmp testing script and net state monitor

2006年8月10日 9点13分 发表评论 阅读评论

I wrote the following scripts to copy and compare bigfiles:
#!/bin/bash
# test script
# /mnt/bigfile is 150G,and /NFS_test is mounted from remote host
# mount 192.168.123.78:/Test /NFS_test

# set counter
COUNTER=0

# loop
while :
do
# copy local file “a” to remote host “b”,and then cmp
echo “—————————-” >> /root/NFS_Rep/time
echo “cp a–>b from: `date`” >> /root/NFS_Rep/time
cp -v /mnt/bigfile /NFS_test/bigfile1 >> /root/NFS_Rep/cp_ab 2>&1
echo “cp a–>b end: `date`” >> /root/NFS_Rep/time
echo ” ” >> /root/NFS_Rep/time

# sleep time
sleep 60

#starrt cmp
echo “cmp a–>b from: `date`” >> /root/NFS_Rep/time
cmp -l /mnt/bigfile /NFS_test/bigfile1 >> /root/NFS_Rep/cmp_ab 2>&1
echo “cmp a–>b end: `date`”>> /root/NFS_Rep/time
echo ” ” >> /root/NFS_Rep/time

# sleep time
sleep 60

# copy local file “a” to remote host “c”,and then cmp
echo “cp a–>c from: `date`” >> /root/NFS_Rep/time
cp -v /mnt/bigfile /NFS_test/bigfile2 >> /root/NFS_Rep/cp_ac 2>&1
echo “cp a–>c end: `date`” >> /root/NFS_Rep/time
echo ” ” >> /root/NFS_Rep/time

#sleep time
sleep 60

#start cmp
echo “cmp a–>c from: `date`” >> /root/NFS_Rep/time
cmp -l /mnt/bigfile /NFS_test/bigfile2 >> /root/NFS_Rep/cmp_ac 2>&1
echo “cmp a–>c end: `date`” >> /root/NFS_Rep/time
echo ” ” >> /root/NFS_Rep/time

#sleep time
sleep 60

# compare “b” and “c”
echo “cmp b–>c from: `date`” >> /root/NFS_Rep/time
cmp -l /NFS_test/bigfile1 /NFS_test/bigfile2 >> /root/NFS_Rep/cmp_bc 2>&1
echo “cmp b–>c end: `date`” >> /root/NFS_Rep/time
echo “—————————-” >> /root/NFS_Rep/time

# delete “b” and “c”
rm -rf /NFS_test/bigfile1
rm -rf /NFS_test/bigfile2

# reset the counter
COUNTER=`expr $COUNTER + 1`
echo “The loop counter is $COUNTER” > /root/NFS_Rep/counter.rep
done

This script would create 7 report files in /root/NFS_Rep directory: cp_ab,cmp_ab,cp_ac.cmp_ac,cmp_bc,counter.rep,time.
Note,I’ve made some mistakes when wrote $ as &, and the cmp showed error when it had taken a very long time to complete copy bigfile(150G), how sadly I am! This issue gave me a good lesson, it was better to use small files to test the scripts beforn running it in order to checking the code and saving time. Late, I modified the script again with adding “date” marks.

Due to the network configuration of “192.168.123.78” changed automatically in the day before yesterday, I was very caring the remote host’s net state, so writing the following script:
# !/bin/bash
# test 192.168.123.78
while :
do
if ping -c 1 192.168.123.78 > /dev/null 2>&1
then
echo “At `date` : The status:192.168.123.78 is ok” > /root/net_report
sleep 300
else
echo “At `date` : Warning, the remote host maybe lost!!!” >> /root/net_report
wall “Warning, the remote host 192.168.123.78 maybe lost!!!”
fi
done

This script will monite the remote host’s network, and create report.

分类: 科技 标签:
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.
您必须在 登录 后才能发布评论.