Linux Bash脚本生成空文件
我已经创建了一个脚本,这样我可以在特定路径中搜索0kb的文件,输出将被重定向到文本文件,然后通过电子邮件发送。该脚本可以工作,但当发送电子邮件或在脚本运行后查看时,fie是空的Linux Bash脚本生成空文件,linux,bash,Linux,Bash,我已经创建了一个脚本,这样我可以在特定路径中搜索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.t
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
我猜你想要这样的东西:
# 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
我猜你想要这样的东西:
# 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
我猜你想要这样的东西:
# 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
您已明确指示截断
/tmp/output.txt
。你为什么期望那里有满足感?你想达到什么目的?我猜/tmp/output.txt
应该在$()
中。你已经明确指示要截断/tmp/output.txt
。你为什么期望那里有满足感?你想达到什么目的?我猜/tmp/output.txt
应该在$()
中。你已经明确指示要截断/tmp/output.txt
。你为什么期望那里有满足感?你想达到什么目的?我猜/tmp/output.txt
应该在$()
中。你已经明确指示要截断/tmp/output.txt
。你为什么期望那里有满足感?你想达到什么目的?我猜/tmp/output.txt
应该在$()
中,测试总是会失败。尝试“查找…”/tmp/output.txt;如果[[-n/tmp/output.txt]…`@williampersell该测试将始终通过:)使用-s
我建议使用这个很棒的黑客:如果找到grep”“>文件
wc-l文件输出0文件
,而不仅仅是0
。对于这种方法,您可以使用[[-s
,它检查非空文件并避免计算行数。在fi
之后需要rm/tmp/output.txt
,这样即使是空的文件也会被删除。可以说,名称应该用$$
修饰或用mktemp
命令创建。测试总是会失败。请尝试“查找…”/tmp/output.txt;if[-n/tmp/output.txt]…`@williampersell该测试将始终通过:)使用-s
我建议使用这个很棒的黑客:如果找到..grep”“>文件
wc-l文件输出0文件
,而不仅仅是0
。对于这种方法,你可以使用[[-s
,它检查非空文件并避免计算行数。在fi
之后需要rm/tmp/output.txt
,这样即使是空的文件也会被删除。可以说,名称应该用$$
修饰或用mktemp
命令创建。测试总是会失败。请尝试“查找…”/tmp/output.txt;if[-n/tmp/output.txt]…`@williampersell该测试将始终通过:)使用-s
我建议使用这个很棒的黑客:如果找到..grep”“>文件
wc-l文件输出0文件
,而不仅仅是0
。对于这种方法,你可以使用[[-s
,它检查非空文件并避免计算行数。在fi
之后需要rm/tmp/output.txt
,这样即使是空的文件也会被删除。可以说,名称应该用$$
修饰或用mktemp
命令创建。测试总是会失败。请尝试“查找…”/tmp/output.txt;if[-n/tmp/output.txt]…`@williampersell该测试将始终通过:)使用-s
我建议使用这个很棒的黑客:如果找到..grep”“>文件
wc-l文件输出0文件
,而不仅仅是0
。对于这种方法,你可以使用[[-s
,它检查非空文件并避免计算行数。您需要在fi
之后添加rm/tmp/output.txt
,这样即使文件为空也会将其删除。可以说,名称应该用$$
修饰或使用mktemp
命令创建。