简体   繁体   English

Bash脚本产生空文件

[英]Bash script produces empty file

I have created a script so I can search for 0kb files in a certain path, the output is to be redirected to a text file and then emailed. 我已经创建了一个脚本,因此我可以在某个路径中搜索0kb文件,将输出重定向到文本文件,然后通过电子邮件发送。 The script works except that the fie is empty either when it's emailed or when it's viewed after the script runs. 该脚本起作用,除了在发送电子邮件或在脚本运行后查看时,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   

Not sure if I missed something so any help would be appreciated. 不知道我是否错过了什么,所以将不胜感激。

Thanks 谢谢

I guess you want something like this: 我想你想要这样的东西:

# 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