<分区>
所以我尝试运行一个脚本,该脚本在 df -h 的内容中搜索超过阈值的目录,基本上是在该目录上运行查找命令以获取前十个最大的文件,然后停止运行查找。但是,当它按预期给出前十个文件时,它会多次吐出:
find: ‘ls’ terminated by signal 13
我的问题很简单,我该如何阻止这些?我想我明白这些是由于我的 find 命令和 head -n 10 命令同时运行,因为 head 在 find 之后通过管道传输,但如果有人能详细说明,那就太好了。我的目标是将其提交给正在工作的权力机构(沃尔玛),以便它开始在我们的测试服务器上运行。
另请注意,find 命令中的大小仅为 5M,因为我的测试服务器上没有 10 个在该目录中那么大的文件。
这是脚本:
#!/bin/bash
#defines what exceeds threshold
threshold="90%|91%|92%|93%|94%|95%|96%|97%|98%|99%|100%|6%"
#puts the output of df -h into output_df
df -h > output_df
cat output_df | awk -v VAR=$threshold '{if($5~VAR)print $6}' > exceeds_thresh
LINES=()
while IFS= read -r exceeds_thresh
do
find $exceeds_thresh -xdev -size +5M -exec ls -lah {} \; | head -n 10
done < "exceeds_thresh"
#cleaning up the files the script created
rm output_df exceeds_thresh
这是一个示例输出:
-rw-r-----+ 1 root systemd-journal 16M Jun 1 19:18 /var/log/journal/a237b5bc574941af85c796e15b0ce420/system.journal
-rw-r-----+ 1 root systemd-journal 8.0M May 29 05:38 /var/log/journal/a237b5bc574941af85c796e15b0ce420/system@00056d51a41389f0-0c1bef27b9d68ad6.journal~
-rw-r-----+ 1 root systemd-journal 104M Jun 1 05:55 /var/log/journal/a237b5bc574941af85c796e15b0ce420/system@45697f9ed4b84f07b92c5fcbc8a945bd-0000000000000001-00056d51a40f2f0c.journal
find: ‘ls’ terminated by signal 13
find: ‘ls’ terminated by signal 13
find: ‘ls’ terminated by signal 13
find: ‘ls’ terminated by signal 13
find: ‘ls’ terminated by signal 13
find: ‘ls’ terminated by signal 13
find: ‘ls’ terminated by signal 13
find: ‘ls’ terminated by signal 13