以下範列是搜尋出檔案,產生出清單後,一比一比,對照另個清單動作(mv)
=======================分格線==========================
#!/bin/bash
backerno=( $@ ) ;
path_source="/data/mail/mailpool/" ;
dest="/data/mail/dest" ;
yahoodest="/data/mail/yahoodest"
dest_no=`cat $dest |wc -l` ;
yahoodest_no=`cat $yahoodest|wc -l`
yahoolist="/opt/logs/yahoo`date +%Y%m%d_%H_%M`_${backerno[0]}_$RANDOM"
filelist="/dev/shm/`date +%Y%m%d_%H_%M`_${backerno[0]}_$RANDOM"
create_list ()
{
if [ ${#backerno[*]} -eq 0 ];then
echo "Userage: cmd
else
si=0;
while [ $si -lt ${#backerno[*]} ]
do
echo ${backerno[$si]} create list done ;
#find $path_source${backerno[$si]} -name '*.?mail' |head -2000 |xargs grep -i "^To.*@yahoo.*" | awk -F ':' '{print $1}' >> $yahoolist --> 此行是當初要抓出,要寄到yahoo信件所做的分頪
find $path_source${backerno[$si]} -name '*.?mail' |head -800 | awk -F ':' '{print $1}' >> $filelist
#find $path_source${backerno[$si]} -name '*.?mail' -print >> $filelist
si=`expr $si + 1`;
done
fi
}
random_send ()
{
destogo=`awk 'NR=='$i'' $dest`
mv -f $@ $destogo
i=`expr $i + 1 ` }
yahoo_send ()
{
destogo=`awk 'NR=='$i'' $yahoodest`
mv -f $@ $destogo
#echo $@ ==== $destogo
#echo "$@ move to $destogo"
i=`expr $i + 1 ` }
random_main ()
{
i=1
for file in `cat $filelist`
do
if [ $i -gt $dest_no ];then
i=1
random_send $file
else
random_send $file
fi
done }
yahoo_main ()
{
i=1
for file in `cat $yahoolist`
do
if [ $i -gt $yahoodest_no ];then
i=1
yahoo_send $file
else
yahoo_send $file
fi
done }
x=1;
while [ $x -ge 1 ]
do
starttime=`date +'%Y%m%d %T'`
perstart=`date +%s`
create_list
echo $filelist
random_main
perstop=`date +%s`
tvalue=`expr $perstop - $perstart`
totalfiles=`cat $filelist |wc -l`
pervalue=`expr $totalfiles / $tvalue `
echo "Start at $starttime done at `date +'%Y%m%d %T'` moved $totalfiles files in $pervalue per/sec" >> /data/mail/log/${backerno[0]}${backerno[1]}.log;
rm -rf $filelist ;
sleep 60;
done
留言列表