0

メールアカウントをチェックし、スクリプトの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
4

1 に答える 1