我正在尝试创建我的树莓派的打印服务。这个想法是要有一个pop3帐户来进行打印作业,我可以在其中发送PDF文件并让他们在家打印。因此,我设置了fetchmail→ procmail和rarr; uudeview收集电子邮件(使用白名单),提取文档并将其保存到/home/pi/attachments/
。至此,一切都正常了。
为了打印文件,我想设置一个shell脚本,我计划每分钟通过cronjob执行一次。那就是我现在停留的地方,因为我收到“权限被拒绝”消息,并且在手动执行命令时,脚本工作时什么都没打印。
这是我的脚本的样子:
#!/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 [email protected] 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 [email protected]@SERVER.HOSTER.TLD:1 of 1 (32139 octets) flushed
mail2print.sh: 6: mail2print.sh: /home/pi/attachments/Stage2.pdf: Permission denied
电子邮件是从pop3帐户中提取的,附件被提取并出现一会儿~/attachements/
,然后被删除。但是没有打印输出。
有什么想法我做错了吗?
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
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句