我有一个下面的 shell 脚本,它检查电子邮件帐户并自动将附件打印到脚本第 8 行列出的打印机。您能否帮我修改它,使第 8 行是一个变量,并且可以通过在电子邮件正文中插入适当的文本 PRINTER=FOO 来设置该变量。这将允许脚本打印到多台打印机。
#!/bin/bash
#while [ 1 ]
while [ 1 ]
do
SUPPORTED_FILETYPES=".pdf"
#LP_OPTIONS="-o media=A4,tray1 -o fit-to-page -o position=top -o scaling=100"
LP_OPTIONS=""
PRINTER="PRT04-3" #line no. 8
MAILFILE=~/eprint/$(date +%H%M%S).txt
PRINT_FOLDER=~/eprint/printable
/usr/bin/fetchmail --bsmtp $MAILFILE
if [ "$?" = "0" ]; then
MAIL_ADDRESS=$(grep 'From:' $MAILFILE | sed -n -e 's/^[^<]*<\([^>]*\)>.*$/\1/p')
/usr/bin/uudeview +e $SUPPORTED_FILETYPES -p $PRINT_FOLDER -i $MAILFILE
rm $MAILFILE
PRINTED="no"
for f in $PRINT_FOLDER/*
do
if [ "$f" != "$PRINT_FOLDER/*" ]; then
LP_OUTPUT=$(lp $LP_OPTIONS "$f" -d $PRINTER)
if [ "$?" != "0" ]; then
MAILTEXT="File "$f" could not be printed."
echo "$MAILTEXT" | mail -s "Print-Error" $MAIL_ADDRESS
fi
rm "$f"
PRINTED="yes"
else
if [ "$PRINTED" = "no" ]; then
echo "No printable Attachments" | mail -s "Print-Error" $MAIL_ADDRESS
fi
fi
done
# ~/mailprint
fi
sleep 4
done