我在mailq上運行一個shell腳本來創建一個要刪除的文件列表,但由於權限的限制,我無法用shell腳本刪除它們(當我使用root權限時,腳本可以工作,但是我不能總是爲根權限提供root密碼給用戶)。我想將輸出的文件列表發送給perl以刪除它們,並且Perl程序具有root權限。如何使用shell腳本輸出作爲perl腳本的輸入(刪除具有權限的文件)?
shell腳本是:
#!/usr/bin/ksh
WORKFILE="/tmp/check.mq"
MAILLIST="[email protected]"
mailq|grep -B1 -i temporarily |grep -iv deferred |egrep -i 'jan|feb|mar|apr|may|june|jul|aug|sept|oct|nov|dec' |awk -F" " '{print $1}' |awk '{print substr($0,10,14)}'|tee $WORKFILE |awk '{print "*" $1}'|tee mail.mq
mailq|grep -B1 -i unknown |egrep -i 'jan|feb|mar|apr|may|june|jul|aug|sept|oct|nov|dec' |awk -F" " '{print $1}' |awk '{print substr($0,10,14)}'|tee $WORKFILE |awk '{print "*" $1}'|tee mail.mq
mailq|grep -B1 -i lookup |grep -iv deferred |egrep -i 'jan|feb|mar|apr|may|june|jul|aug|sept|oct|nov|dec' |awk -F" " '{print $1}' |awk '{print substr($0,10,14)}'|tee $WORKFILE |awk '{print "*" $1}'|tee mail.mq
cat mail.mq | while read file; do rm /var/spool/mqueue/$file;done
find . -type f -name "mail.mq" |rm -rf mail.mq
它創建類似的輸出:
*##### where ##### is a unique 5 numbers to identify files in the mailq.
我想知道我可以刪除與任何用戶root priveleges這些文件。
這就像你有一些嚴重的問題,架構在這裏,如果你不能刪除文件,但有機會獲得一個Perl程序,可以對我聽起來。在添加更多口香糖和吐出孔之前,我會努力解決這個問題。 – 2012-04-17 14:51:53