find /root/app/tcu/data/log/.log -mtime +2 -type f |xargs -i gzip {} find /root/app/tcu/data/log/.log.0 -mtime +2 -type f |xargs -i gzip {} find /root/app/tcu/data/log/.log.1 -mtime +2 -type f |xargs -i gzip {} find /root/app/tcu/data/log/.log.2 -mtime +2 -type f |xargs -i gzip {} find /root/app/tcu/data/log/.log.3 -mtime +2 -type f |xargs -i gzip {} find /root/app/tcu/data/log/.log.4 -mtime +2 -type f |xargs -i gzip {} # /root/app/tcu/data/ccuLog find /root/app/tcu/data/ccuLog/.log -mtime +2 -type f |xargs -i gzip {} find /root/app/tcu/data/ccuLog/.log.0 -mtime +2 -type f |xargs -i gzip {} find /root/app/tcu/data/ccuLog/.log.1 -mtime +2 -type f |xargs -i gzip {} find /root/app/tcu/data/ccuLog/.log.2 -mtime +2 -type f |xargs -i gzip {} find /root/app/tcu/data/ccuLog/.log.3 -mtime +2 -type f |xargs -i gzip {} find /root/app/tcu/data/ccuLog/.log.4 -mtime +2 -type f |xargs -i gzip {} # /root/app/remote/data/log find /root/app/remote/data/log/.log -mtime +2 -type f |xargs -i gzip {} find /root/app/remote/data/log/.log.0 -mtime +2 -type f |xargs -i gzip {} find /root/app/remote/data/log/.log.1 -mtime +2 -type f |xargs -i gzip {} find /root/app/remote/data/log/.log.2 -mtime +2 -type f |xargs -i gzip {} find /root/app/remote/data/log/.log.3 -mtime +2 -type f |xargs -i gzip {} find /root/app/remote/data/log/.log.4 -mtime +2 -type f |xargs -i gzip {} 改成循环语句,文件夹内的.gz文件不进行压缩,要用#!bin/bin/sh方式
时间: 2023-09-26 14:14:12 浏览: 178
基于ARM和μC/OS-II的车载定位终端的设计
#!/bin/bash
# Define the directories to be searched
directories=(/root/app/tcu/data/log /root/app/tcu/data/ccuLog /root/app/remote/data/log)
# Loop through the directories
for dir in "${directories[@]}"
do
# Loop through the log files in the directory
for log_file in "$dir"/*.log*
do
if [[ -f "$log_file" && ! "$log_file" =~ \.gz$ ]]; then
# Check if the file is older than 2 days and if it is not already compressed
if [[ "$(find "$log_file" -mtime +2 -type f | wc -l)" -gt 0 && ! -f "${log_file}.gz" ]]; then
# Compress the file
gzip "$log_file"
fi
fi
done
done
echo "Compression complete!"
阅读全文