
/srv/mutt
ディレクトリ内のファイルを表示するためにシステムの起動時に実行される次のbashスクリプトがあります。しばらくの間は完璧に動作しますが、到着するファイルを「見る」ことは停止します/srv/mutt
。
問題を診断するためにechoステートメントを追加しました。これはinotifywait
、ファイルを報告して報告しましたが、ビュー/tmp/waitAndView.log
プログラムが呼び出されなかったことを示します。
何が間違っていますか?原因や問題の診断方法に関するアイデアがある人はいますか?そうだ」
#!/bin/bash
#
#
# script to detect new files in /srv/mutt and display them, run from 'Session & Startup'
#
cd /srv/mutt # where the files appear
shopt -s nocasematch # ignore case in case (erk!)
#
#
# inotifywait will output the name of any file that is rsynced into /srv/mutt
#
inotifywait -m -q -e moved_to --format %f /srv/mutt/ | \
#
#
# Handle file as appropriate
#
while read -r file; do
echo $file >>/tmp/waitAndView.log
case $file in
dbapost*)
#
#
# run dbapost on the received message file
#
/home/chris/.cfg/bin/dbapost $file &
;;
*.pdf)
#
#
# View PDF file with atril
#
atril $file &
;;
*.jpg|*.png|*.jpeg)
#
#
# View other image formats with nomacs
#
nomacs $file &
;;
*.html)
#
#
# HTML file is an E-Mail to view with web browser
#
$HOME/bin/browser --new-tab file:///srv/mutt/$file &
;;
*)
;;
esac
echo finished with $file >>/tmp/waitAndView.log
done
答え1
この文で実行されるプログラムの1つcase
は、入力を盗むことです。次の例を考えてみましょう。
seq 9 |
while read f
do case $f in
4) cat -n & ;;
*) echo got $f ;;
esac
done
次のような結果が出ることがあります。
got 1
got 2
got 3
1 6
2 7
3 8
4 9
got 5
一度起動すると、cat
成功する前にパイプを読むことができます。通常、「ブラウザ」コマンドなどをwhile read
追加して標準入力をオフにする必要があります。</dev/null