Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux Bash脚本生成空文件_Linux_Bash - Fatal编程技术网

Linux Bash脚本生成空文件

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

我已经创建了一个脚本,这样我可以在特定路径中搜索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

我猜你想要这样的东西:

# 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
命令创建。