这是我正在使用的代码段。如您所见,shell停止执行,并且不会继续执行elif语句。
if [[ $( cat /tmp/findout |wc -l) -ge 1 ]];then
echo "Found files older than 14 days and deleting them......"
xargs -d'\n' rm -v </tmp/findout
elif [[ $(du -sm /var/log |awk '{print $1+0}') -ge $cdu ]];then
echo "Verifying the /var/log usage......"
fsusage
[root@myhost]# sh rvarlog_util.sh
Found files older than 14 days and deleting them......
removed ‘/var/log/messages-20190210’
removed ‘/var/log/pxp-agent.log-20190313.gz’
removed ‘/var/log/pxp-agent.log-20190315.gz’
removed ‘/var/log/cron-20190210’
removed ‘/var/log/pmd.log.6.gz’
removed ‘/var/log/cron-20190303’
removed ‘/var/log/pxp-agent.log-20190309.gz’
[root@myhost]#
答案 0 :(得分:0)
通过添加;如下所示,在xargs行的结尾帮助了我
xargs -I{} sh -c 'rm -v {}' </tmp/findout | tee /tmp/srsvar.log >/dev/null 2>&1 ;
echo "Deleted file names have been stored in /tmp/srsvar.log"