我试图通过我的覆盆子pi创建一个打印服务。我的想法是为打印作业设置一个pop3帐户,我可以在那里发送PDF文件并在家里打印。因此我设置了fetchmail& RARR; procmail& RARR; uudeview收集电子邮件(使用白名单),提取文档并将其保存到/home/pi/attachments/
。到目前为止,一切正常。
要打印文件,我想设置一个shell脚本,我计划每分钟通过cronjob执行一次。那是我现在被困住的地方,因为我被拒绝了#34;消息,并且在手动执行命令时,脚本完全没有打印任何内容。
这就是我的脚本:
#!/bin/bash
fetchmail # gets the emails, extracts the PDFs to ~/attachments
wait $! # takes some time so I have to wait for it to finish
FILES=/home/pi/attachments/*
for f in $FILES; do # go through all files in the directory
if $f == "*.pdf" # print them if they're PDFs
then
lpr -P ColorLaserJet1525 $f
fi
sudo rm $f # delete the files
done;
sudo rm /var/mail/pi # delete emails
执行脚本后,我得到以下反馈:
1 message for print@MYDOMAIN.TLD at pop3.MYDOMAIN.TLD (32139 octets).
Loaded from /tmp/uudk7XsG: 'Test 2' (Test): Stage2.pdf part 1 Base64
Opened file /tmp/uudk7XsG
procmail: Lock failure on "/var/mail/pi.lock"
reading message print@MYDOMAIN.TLD@SERVER.HOSTER.TLD:1 of 1 (32139 octets) flushed
mail2print.sh: 6: mail2print.sh: /home/pi/attachments/Stage2.pdf: Permission denied
从pop3帐户中提取电子邮件,提取附件并在~/attachements/
中短暂显示,然后删除。但是没有打印输出。
任何想法我做错了什么?
答案 0 :(得分:2)
if $f == "*.pdf"
应该是
if [[ $f == *.pdf ]]
我也认为
FILES=/home/pi/attachments/*
应该引用:
FILES='/home/pi/attachments/*'
建议:
#!/bin/bash
fetchmail # gets the emails, extracts the PDFs to ~/attachments
wait "$!" # takes some time so I have to wait for it to finish
shopt -s nullglob # don't present pattern if no files are matched
FILES=(/home/pi/attachments/*)
for f in "${FILES[@]}"; do # go through all files in the directory
[[ $f == *.pdf ]] && lpr -P ColorLaserJet1525 "$f" # print them if they're PDFs
done
sudo rm -- "${FILES[@]}" /var/mail/pi # delete files and emails at once
答案 1 :(得分:-1)
使用下面的方法首先过滤pdf文件,然后在for循环中删除if语句。
FILES="ls /home/pi/attachments/*.pdf"