Linux 超过7天的Gzip或tars日志
需要创建一个脚本,该脚本将在多(3)个路径/home/temp、home/logs中创建超过7天的Gzip或tars日志,然后确认此脚本的home/var/lib/mongo容量超过50%。到目前为止,这是我得到的,但我想不出如何将这些结合起来:Linux 超过7天的Gzip或tars日志,linux,bash,Linux,Bash,需要创建一个脚本,该脚本将在多(3)个路径/home/temp、home/logs中创建超过7天的Gzip或tars日志,然后确认此脚本的home/var/lib/mongo容量超过50%。到目前为止,这是我得到的,但我想不出如何将这些结合起来: find . -mtime +7 -print -exec gzip {} \; for all 3 but them find /tmp/log/ -mtime +7 -type f -exec sh -c \ 'tar-czvPf/tmp/ol
find . -mtime +7 -print -exec gzip {} \; for all 3 but them
find /tmp/log/ -mtime +7 -type f -exec sh -c \
'tar-czvPf/tmp/older_log_$(basename$0)$(date+%F).tar.gz$0'{}
# create a single tar file for each archive +7 days old on one mount
如果我正确理解您的意思,您希望将多个旧日志归档到一个tar文件中:
find /tmp/log /home/temp /home/logs -mtime +7 -type f \
| xargs tar -czf /tmp/older_log_$(date +%F).tar.gz --remove-files
为了便于阅读,我把它分为两行
为什么要重新发明轮子?看看: