繁体   English   中英

Bash脚本产生空文件

[英]Bash script produces empty file

我已经创建了一个脚本,因此我可以在某个路径中搜索0kb文件,将输出重定向到文本文件,然后通过电子邮件发送。 该脚本起作用,除了在发送电子邮件或在脚本运行后查看时,fie为空。

if [[ -n $(find /path/to/files/ -type f -empty -mmin +2) ]] then
> /tmp/output.txt ; mail -s "subject" -a /tmp/output.txt "email@address"
rm /tmp/ftr_output.txt
fi   

不知道我是否错过了什么,所以将不胜感激。

谢谢

我想你想要这样的东西:

# Save find results in a text file
find /path/to/files/ -type f -empty -mmin +2 > /tmp/output.txt

# Check that the text file isn't empty (meaning no results from find)
if [ -s /tmp/output.txt ]
then
    # Send the text file along with an email
    mail -s "subject" -a /tmp/output.txt "email@address"
fi
# Remove the text file
rm /tmp/output.txt

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM