- 论坛徽章:
- 0
|
着重看下最底下绿色部分,是我自己的解决方法,不知道可不可以.给点意见,我的方法是把备份的打印文件分成全部打印队列,已经打印队列,正在打印的文件,我的程序还没有测试,在家的windowsxp 自己写的,星期一上班再去测试
#打印程序
trap "" 2 3 15
HOLD1=tmp/HOLD1.$$
HOLD2=tmp/HOLD2.$$
HOLD3=tmp/HOLD3.$$
HOLD4=tmp/HOLD4.$$
DWFILE=dfgz/DWFILE.INI #单位信息 记录1,单位编号 2,单位名称 3. 局所号
PRTNOW=dfgz/prtnow.log #正在打印的文件 记录1.终端端口号 2单位编号 3.正在打印的文件名
PRTOVER=dfgz/prtover.log #已经打印完的文件 1.打印文件名 2.单位编号 3.终端端口号
PRTLIST=dfgz/PRTLIST.log #所有打印文件
PRTTTY=dfgz/prttty.log #终端端口号,多终端打印
if [ ! -d "backup" ];then
mkdir backup
fi
if [ ! -d "dfgz" ];then
mkdir dfgz
fi
if [ ! -f $DWFILE ];then
>$DWFILE
fi
if [ ! -f $PRTLIST ];then
>$PRTLIST
fi
if [ ! -f $PRTNOW ];then
>$PRTNOW
fi
if [ ! -f $PRTOVER ];then
>$PRTOVER
fi
if [ ! -f $PRTTTY ];then
>$PRTTTY
fi
#数据录入
#1.名称2.长度(汉字随便但必须要输)3.number数字/chinachar汉字4.null可空/no不可空5.提示信息
null_rec()
{
_XSTR=$1
_NLEN=$2
_CHARORNUM=$3
_SNULL=$4
_MSG=$5
_RSTR=""
while :
do
if [ "$Q_FLAG" = "0" ];then
break
fi
clear
dispaly_rec
echo "$_MSG"
echo "请输入${_XSTR}为${_NLEN}位数字或者输入q退出:"
echo -n "\n请输入${_XSTR}为${_NLEN}位数字:"
read _RSTR
if q_quit $_RSTR
then
Q_FLAG=0
_RSTR=""
break
else
Q_FLAG=1
fi
if [ "$_RSTR" != "" ];then
if a_number $_RSTR;then
CZH_PASS=0
else
CZH_PASS=1
fi
if length_check $_RSTR $_NLEN;then
CZH_LEN=0
else
CZH_LEN=1
fi
if characters $_RSTR;then
CZH_CHAR=0
else
CZH_CHAR=1
fi
if [ "$_CHARORNUM" = "number" ];then
if [ "$CZH_LEN" = "0" -a "$CZH_PASS" = "0" ]
then
break
else
echo "${_XSTR}必须为${_NLEN}位数字,不能含有字母"
echo "${_XSTR}输入错误。"
continue_prompt
fi
fi
if [ "$_CHARORNUM" = "chinachar" ];then
if [ "$CZH_CHAR" = "0" ]
then
break
else
H_NLEN=`echo $_NLEN%2|bc`
echo "${_XSTR}必须为汉字"
echo "${_XSTR}输入错误。"
continue_prompt
fi
fi
else
if [ "$_SNULL" = "null" ];then
break
fi
if [ "$_SNULL" = "no" ];then
echo "${_XSTR}不能为空"
continue_prompt
fi
fi
done
}
#检测字长
length_check()
{
_STR=$1
_MAX=$2
_LENGTH=`echo $_STR|awk '{print length($0)}'`
if [ "$_LENGTH" -ne "$_MAX" ];then
return 1
else
return 0
fi
}
#检测是否为数字
a_number()
{
_NUM=$1
_NUM=`echo $1|awk '{if($0~/[^0-9]/) print "1"}'`
if [ "$_NUM" != "" ]
then
return 1
else
return 0
fi
}
#检测是否为字符型
characters()
{
_LETTERS_ONLY=$1
_LETTERS_ONLY=`echo $1|awk '{if($0~/[^a-zA-Z0-9]/) print "1"}'`
if [ "$_LETTERS_ONLY" != "" ]
then
return 1
else
return 0
fi
}
#检测记录唯一性
check_duplicate()
{
_CODE=$1
_DFILE=$2
MATCH=`grep "^$_CODE" $_DFILE`
#echo $_CODE
if [ "$MATCH" = "" ];then
return 0
else
return 1
fi
}
#拷贝文件
cpfile()
{
_CSFILE=$1
_CDFILE=$2
if [ -f $_MSFILE ];then
cp $_CSFILE $_CDFILE
return 0
fi
}
#正在打印读写权利
now_list()
{
_FLAGNOW=$1
_BACK_FILE=$2
if [ "_FLAGNOW" = "w" ];then
printf "$IS_TTY\t$_BACK_FILE\t$DWBH\n" >>$PRTNOW
return 1
else
if [ "$_FLAGNOW" = "r" ];then
NOW_FLAGR=`grep "$_BACK_FILE" $PRTNOW`
if [ "$NOW_FLAGR" != "" ]
then
return 1
else
return 0
fi
fi
fi
}
#已经打印读写权利
over_list()
{
_FLAGOVER=$1
_BACK_FILE2=$2
if [ "$_FLAGOVER" = "w" ];then
printf "$_BACK_FILE2\t$DWBH\t$IS_TTY\n" >>$PRTOVER
grep -v "^$IS_TTY" $PRTNOW >>$HOLD2
mv $HOLD2 $_NOWLIST
return 1
else
if [ "$_FLAGOVER" = "r" ];then
OVER_FLAGR=`grep "$_BACK_FILE2" $PRTOVER`
if [ "$OVER_FLAGR" != "" ];then
return 1
else
return 0
fi
fi
fi
}
#打印功能
prtfile()
{
_PRTFILE=$1
echo "[5i"
cat $_PRTFILE
echo "[4i"
}
#打印到终端
prttty()
{
_PRTFILE2=$1
_MYTTY=$2
now_list w $_PRTFILE2
if [ "$_MYTTY" != "" -a -f "$_PRTFILE2" ];then
prtfile ${_PRTFILE2} >${_MYTTY}
over_list w $_PRTFILE2
else
echo "要打印的文件不存在,或者端口不存在"
fi
}
#文件是否相同
diffile()
{
_DIFFILE1=$1
_DIFFILE2=$2
if [ -f "$_DIFFILE1" -a -f "$_DIFFILE2" ];then
diff ${_DIFFILE1} ${_DIFFILE2} >$HOLD1
if [ $? -ne 0 ];then
return 0
else
return 1
fi
fi
}
#备份文件并打印文件
reportbackup()
{
null_rec "单位编号" 8 number no "请输入单位编号,输入q退出"
DWBH=$_RSTR
if ! check_duplicate $DWBH $DWFILE;then
REORTFILE=/mid_SYS/run/tmp/rpt${DWBH}#需要备份的文件
whlie :
do
LASTFILE=`awk '{if($2=='$DWHB') print $0}' $PRTLIST|tail -1|awk '{print $1}'`#最后一个文件
if diffile $REORTFILE $LASTFILE;then #比较两个文件
PRTNUM=`awk '{if($2=='$DWHB') print $0}' $PRTLIST|wc -l`
PRTNUM=`expr $PRTNUM + 1 `
PRTNUM=`expr $RPTNUM + 1000 `
BACKUPFILE=backup/prt${DWBH}${PRTNUM}
cpfile $REORTFILE $BACKUPFILE
printf "$BACKUPFILE\t$DWBH\n" >>$PRTLIST
PRTLIST_FILE='awk '{printf $1}$PRTLIST`
TTY_LIST='awk '{printf $1}$PRTTTY`
for $PRT_FIIE in $PRTFILE_FILE
do
if now_list r $PRT_FILE;then
NOW_FLAG=0
else
NOW_FLAG=1
fi
if over_list r $PRT_FILE;then
OVER_FLAG=0
else
OVER_FLAG=1
fi
if [ "$NOW_FLAG" = "0" -a "$OVER_FLAG" = "0" ];then
for IS_TTY in $TTY_LIST
do
if check_duplicate $IS_TTY $PRTNOW;then
prttty $PRT_FILE $IS_TTY &
else
echo "\n所有打印机忙,无法打印"
fi
echo "等待60秒继续监测文件"
sleep 60
done
done
fi
done
else
echo "\n你输入单位编号不存在\n"
fi
}
[ 本帖最后由 liujuejun 于 2008-3-23 10:35 编辑 ] |
|