logrotate与crontab

Linux任务执行机制

Linux的任务调度机制主要分为两种:

  1. 执行一次:将在某个特定的时间执行任务调度 ------at

  2. 执行多次:定时任务,每过一段时间执行一次 ------crontab

  3. 关机后执行:关机后恢复尚未执行的程序 -----anacron

at

指定的时间执行一次命令。at有一套相当负责的指定时间的方法,如下表所示:

格式实例解释
HH:MM01:01下一个1点一分执行
HH:MM YYYY-MM-DD/YYYY.MM.DD01:00 2022-3-24具体的时间执行
HH:MM[am/pm]+number[minutes/hours/days/weeks]now+3days某个他具体的时间过了多久之后执行

at命令

date:确认当前系统时间 atq/at -l:查看已经设置但还未执行的任务 atrm [任务序号]/at -d [任务序号]:删除指定的at任务 Ctrl+D:提交任务

示例

# 创建一个新的文件接收信息
[root@ecs-2689 application]# touch test.txt
​
# 执行定时任务
[root@ecs-2689 application]# at 21:00
warning: commands will be executed using /bin/sh
at>  ps aux | wc -l >/var/log/application/test.txt
at> <EOT>   # 任务设置完毕后按 Ctrl+D 组合键提交
job 6 at Thu Mar 24 21:00:00 2022
​
# 到时间查看文件中的内容
[root@ecs-2689 application]# cat test.txt
101
​
# 查看当前时间
[root@ecs-2689 application]# date
Thu Mar 24 21:00:50 CST 2022
​
​
# atq查看设定但未执行的任务 
[root@ecs-2689 application]# atq
7   Fri Mar 25 21:00:00 2022 a root
8   Thu Mar 24 21:10:00 2022 a root
​
# atrm删除指定的任务
[root@ecs-2689 application]# atrm 7
[root@ecs-2689 application]# atq
8   Thu Mar 24 21:10:00 2022 a root

anacron

anacron和crontab同样是多次执行一个任务,但是和crontab不同的是crontab是周期性的在某个时间点执行某个任务而anacron则是经过某段时间检测任务是否执行若没执行则会去执行

在Centos 6.x之前的操作系统中如果使用了anacron服务,则必须安装anacron软件包并且anacron服务必须在运行,可以通过/sbin/service anacron status来判断。在Centos 6.x之后的操作系统中,anacron不再是单独的服务,而变成了系统命令。

相关文件

文件名文件路径解释
anacron检测周期/var/spool/anacron/cron.{daily/weekly/monthly}记录上一次执行的cron 时间和当前时间作比较,如果两个时间差超过了anacron的指定时间差值,证明有cron任务被执行
anacron配置文件/etc/anacrontabanacron的配置文件,可以不需要用anacron命令只需要配置此文件就可以设置anacron定时任务执行

anacrontab

查看anacrontab

[root@ecs-2689 anacron]# cat /etc/anacrontab
# /etc/anacrontab: configuration file for anacron
​
# See anacron(8) and anacrontab(5) for details.
​
# 指定了系统要使用哪个shell
SHELL=/bin/sh
# 指定了系统执行命令的路径
PATH=/sbin:/bin:/usr/sbin:/usr/bin
# 指定了任务执行信息通过电子邮件发给哪些用户
MAILTO=root
# the maximal random delay added to the base delay of the jobs
# 表示anacron在执行任务前先延时一段随机的时间再执行,这段随机的时间为0-45分钟之内的随机数。
RANDOM_DELAY=45
# the jobs指定了只有在凌晨3点到晚上22点这个时间段内才允许执行任务。 will be started during the following hours only
# 指定了只有在凌晨3点到晚上22点这个时间段内才允许执行任务。
START_HOURS_RANGE=3-22
​
#period in days   delay in minutes   job-identifier   command
# period in days :轮回天数表示多长时间执行一次
# delay in minutes :表示启动anacron和运行作业之间的延迟,单位为分钟。前提是最后一次运行之后所经过的时间超出了轮回天数。这个时间加上RANDOM_DAILY中设置的时间是真正的延时时间
# job-identifier : 时间标识符,anacron在执行任务时,会将日期写入/var/spoolanacron/$job-identifier中去
# commend :实际运行的命令。这里的run-parts是一个运行指定目录中所有程序与脚本的命令
​
# run-parts:遍历目标文件夹,执行第一层目录下的可执行权限的文件。
# 每天开机 5 分钟后就检查 /etc/cron.daily 目录内的文件是否被执行,如果今天没有被执行,那就执行
1   5   cron.daily      nice run-parts /etc/cron.daily
# 每隔 7 天开机后 25 分钟检查 /etc/cron.weekly 目录内的文件是否被执行,如果一周内没有被执行,就会执行
7   25  cron.weekly     nice run-parts /etc/cron.weekly
# 每隔一个月开机后 45 分钟检查 /etc/cron.monthly 目录内的文件是否被执行,如果一个月内没有被执行,那就执行 
@monthly 45 cron.monthly        nice run-parts /etc/cron.monthly
​

用corn.daily说明/etc/anacrontab的执行过程

  1. 读取 /var/spool/anacron/cron.daily 文件中 anacron 上一次执行的时间。

  2. 和当前时间比较,如果两个时间的差值超过 1 天,就执行 cron.daily 工作。

  3. 只能在 03:00-22:00 执行这个工作。

  4. 执行工作时强制延迟时间为 5 分钟,再随机延迟 0~45 分钟。

  5. 使用 nice 命令指定默认优先级,使用 run-parts 脚本执行 /etc/cron.daily 目录中所有的可执行文件。

常用命令

anacron通常用配置文件来执行,anacron命令一般不使用

选项功能
-f强制执行相关工作,忽略时间戳。
-u更新 /var/spool/anacron/cron.{daily,weekly,monthly} 文件中的时间戳为当前日期,但不执行任何工作。
-s依据 /etc/anacrontab 文件中设定的延迟时间顺序执行工作,在前一个工作未完成前,不会开始下一个工作。
-n立即执行 /etc/anacrontab 中所有的工作,忽略所有的延迟时间。
-q禁止将信息输出到标准错误,常和 -d 选项合用。

crontab*

原理:在Linux中,周期执行的任务一般由cron这个守护进程来处理[ps -ef|grep cron]。cron可以读取一个或者多个配置文件,这些配置文件包含了命令行及其调用时间。cron的配置文件是“crontab”,当安装完成操作系统后,会默认的安装此服务工具并且启动crond进程,crond进程每分钟会定期检查是否有要执行的任务,如果有要执行的任务,就会执行该任务。cron可以让系统在指定的时间去执行某个指定的工作,我们可以使用crontab指令来管理cron机制。

可能有个误区cron的配置文件是crontab,是/etc/crontab。其实配置文件有三处统称为crontab。

cron服务

systemctl start crond //启动服务 systemctl stop crond //关闭服务 systemctl restart crond //重启服务 systemctl reload crond //重新载入配置 systemctl status crond //查看服务状态

crontab -l //查看用户的crontab任务

crontab -r //删除用户的所有crontab任务

crontab -u $用户名 - [option] //在指定用户下执行crontab命令

相关文件

crontab有两个可以直接设置定时任务的地方和一个存放定时任务脚本的地方。另外crontab可以将任务放在/etc/cron.{hourly/daily/weekly/monthly}下面,这样指定了任务之后会按时的去执行不需要一直去写定时任务方程式。

文件名文件路径
用户crontab任务存放/var/spool/cron/{用户}
crontab配置文件/etc/crontab
crontab脚本存放/etc/cron.d
定时任务存放/etc/cron.{hourly/daily/weekly/monthly}

用户任务存放

这个目录下存放的是每个用户包括root的crontab任务,每个任务以创建者的名字命名,比如tom建的crontab任务对应的文件就是/var/spool/cron/tom。一般一个用户最多只有一个文件。在这里面的定时任务可以通过crontab -l查看

[root@ecs-2689 cron]# cat /var/spool/cron/root
*/10 * * * * /opt/oss/servicemgr/ICAgent/bin/manual/mstart.sh > /dev/null 2>&1
* * * * * su - agent -c 'bash /opt/servicestage-agent/servicestage-agent-1.3.34/servicestage-agent-watchdog.sh check'
13 3 * * * su - agent -c 'cd /opt/servicestage-agent/servicestage-agent-1.3.34/;./servicestage-agent-runner -du default'
[root@ecs-2689 cron]# crontab -l
*/10 * * * * /opt/oss/servicemgr/ICAgent/bin/manual/mstart.sh > /dev/null 2>&1
* * * * * su - agent -c 'bash /opt/servicestage-agent/servicestage-agent-1.3.34/servicestage-agent-watchdog.sh check'
13 3 * * * su - agent -c 'cd /opt/servicestage-agent/servicestage-agent-1.3.34/;./servicestage-agent-runner -du default'

crontab配置文件

负责安排由系统管理员制定的维护系统以及其他任务的crontab

[root@ecs-2689 etc]# cat crontab
​
# 指定了系统要使用哪个shell
SHELL=/bin/sh
# 指定了系统执行命令的路径
PATH=/sbin:/bin:/usr/sbin:/usr/bin
# 指定了任务执行信息通过电子邮件发给哪些用户
MAILTO=root
​
# For details see man 4 crontabs
​
# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed
​
# 每三十分钟以root用户执行下面的命令
*/30 * * * * root /usr/sbin/logrotate -s /tmp/agent-logrotate.status /etc/servicestage-agent/agent-logrotate
​

crontab脚本存放

crontab存放了可以执行的crontab脚本的目录/etc/cron.d,在这个目录下的文件指定了/etc/cron.{hourly/daily/weekly/monthly}下面的文件定时的执行,举个例子:

[root@ecs-2689 cron.d]# cat /etc/cron.d/0hourly
# Run the hourly jobs
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# 每小时的01分,系统会以root身份去/etc/cron.hourly这个目录下执行所有可执行的文件
01 * * * * root run-parts /etc/cron.hourly

查看logrotate文件发现并没有写时间方程式但是由于上面的定时任务,这个文件也会定时的执行。即每个小时的01分执行一次

[root@ecs-2689 cron.d]# ll /etc/cron.hourly/
total 8
-rwxr-xr-x. 1 root root  580 Jun  2  2021 0anacron
-rwx------. 1 root root 1447 Jun  2  2021 logrotate
​
[root@ecs-2689 cron.d]# cat  /etc/cron.hourly/logrotate
#!/bin/sh
# Copyright (c) Huawei Technologies Co., Ltd. 2009-2019. All rights reserved.
# Description: logrotate
# Author: wangce
# Create: 2009-02-10
​
TMPF=`mktemp /tmp/logrotate.XXXXXXXXXX`
if [ -f /etc/logrotate.d/yum.rpmnew ];then
    rm -f /etc/logrotate.d/yum.rpmnew
fi
# Delete file and package upgrades concurrently, Cause the upgrade to fail.
if [ -s /etc/logrotate.d/btmp ];then
        > /etc/logrotate.d/btmp
fi
​
if [ -f /etc/logrotate.d/subscription-manager ];then
        rm -f /etc/logrotate.d/subscription-manager
fi
# Delete file and package upgrades concurrently, Cause the upgrade to fail.
if [ -s /etc/logrotate.d/rsyslog ];then
        > /etc/logrotate.d/rsyslog
fi
# Delete file and package upgrades concurrently, Cause the upgrade to fail.
if [ -s /etc/logrotate.d/wtmp ];then
        > /etc/logrotate.d/wtmp
fi
​
if [ -f /etc/logrotate.d/yum.rpmsave ];then
    mv -f /etc/logrotate.d/yum.rpmsave /etc/logrotate.d/yum
fi
​
/usr/sbin/logrotate /etc/logrotate.conf  2>&1 | tee $TMPF
EXITVALUE=${PIPESTATUS[0]}
if [ $EXITVALUE != 0 ]; then
    # tell what went wrong
    /bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
    /bin/logger -t logrotate -f $TMPF
​
    # if logrotate.status is invalid ,remove it;
    LOGROTATE_STATUS=`cat $TMPF |grep logrotate.status`
    if [ -n "$LOGROTATE_STATUS" ]; then
        rm -f /var/lib/logrotate/logrotate.status
        /usr/sbin/logrotate /etc/logrotate.conf > /dev/null 2>&1
    fi
fi
rm -f $TMPF
exit 0
​

crontab.allow/crontab.deny

/var/adm/cron/cron.allow/var/adm/cron/cron.deny这两个文件指定了哪些用户可以使用crontab服务。root用户可以创建、编辑或者删除这些文件。这些文件中的条目是用户登录名,每一行一个名称。如果登录标识和多个登录名称相关联,这个crontab命令采取第一个在/etc/passwd文件中的登录名称。而且,要允许用户启动 cron 作业,应该使用 chuser 命令将 /etc/security/user 文件中的守护程序属性设置为 TRUE。

如果 cron.allow 文件存在,只有在文件中出现其登录名称的用户可以使用 crontab 命令。root 用户的登录名必须出现在 cron.allow 文件中,如果这个文件存在的话。系统管理员可以明确的停止一个用户,通过使用 crontab 命令,同时在 cron.deny 文件中列出用户的登录名。如果只有 cron.deny 文件存在,任一名称没有出现在这个文件中的用户可以使用 crontab 命令。

如果以下一个条件成立,用户将不能使用 crontab 命令:

  • cron.allow 文件和 cron.deny 文件不存在(只允许 root 用户)。

  • cron.allow 文件存在,但用户的登录名并不列在其中。

  • cron.deny 文件存在,并且用户的登录名列在其中。

如果 cron.allowcron.deny 文件都不存在,只有被 root 用户授权的人可以用 crontab 命令提交一个作业。

使用crontab定时执行脚本不要忘了输出重定向> *

如果crontab不重定向输出,并且crontab所执行的命令有输出内容的话,是一件非常危险的事情。因为该输出内容会以邮件的形式发送给用户,内容存储在邮件文件。

如果命令执行比较频繁(如每分钟一次),或者命令输出内容较多,会使这个邮件文件不断追加内容,文件越来越大。而邮件文件一般存放在根分区,根分区一般相对较小,所以会造成根分区写满而无法登录服务器。

所以在添加crontab命令时,无论命令是否有输出,最好都加上输出重定向到文件或者/dev/null中。如下

# /dev/null代表空设备文件
# > 代表重定向到哪里
# 1 表示stdout标准输出,系统默认值是1,
# 2 表示stderr标准错误
# & 表示等同于的意思,2>&1 ,表示2等同于1
# 1>/dev/null 2>&1 表示标准输出和标准错误都重定向到空设备文件,也就是不输出任何信息到终端
​
[root@ecs-2689 cron.d]# cat /etc/cron.d/timezone.cron
-*/15 * * * * root /bin/bash /usr/bin/os_check_timezone_for_rsyslog.sh 1>/dev/null 2>&1

日志管理工具logrotate

logrotate程序是一个日志文件管理工具。用于分割日志文件,删除旧的日志文件并创建新的日志文件,起到“转储作用”。可以节省磁盘空间。

配置文件

Linux系统默认安装logrotate工具,它默认的配置文件在:

  • /etc/logrotate.conf

  • /etc/logrotate.d

logrotate的状态文件目录是:

  • /var/lib/logrotate/logrotate.status 在这个目录下,会记录上次文件的运行状态

logrotate.conf

logrotate.conf是主要的配置文件,这个文件是logrotate的默认配置文件。如果在我们自定义的logrotate文件下没有定义这些属性值,则会默认的读取这里的值。

[root@ecs-2689 logrotate]# cat /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files weekly
# 一周轮转一次
weekly
​
# keep 4 weeks worth of backlogs
# 保留四个备份
rotate 4
​
# create new (empty) log files after rotating old ones
# rotate之后创建一个新的空文件
create
​
# use date as a suffix of the rotated file
#dateext
​
# uncomment this if you want your log files compressed
# 压缩转储后的文件
compress
​
# packages drop log rotation information into this directory
# 自定义的日志转储配置存储的地方
include /etc/logrotate.d
​
# system-specific logs may be also be configured here.

logrotate.d

logrotate.d是一个文件夹,用户可以在这个文件夹下用户可以定义自己的日志转储配置补缺logrotate.conf的缺省值。

[root@ecs-2689 logrotate.d]# cat /etc/logrotate.d/syslog
#Please note:
#nocreate and copytruncate in configuration file are mutually exclusive and can't be configured at the same time,otherwise nocreate have no effect
#create and copytruncate in configuration file are mutually exclusive and can't be configured at the same time,otherwise create have no effect
/var/log/cron
/var/log/maillog
/var/log/messages
/var/log/secure
/var/log/spooler
{
    maxage 365
    rotate 30
    notifempty
    compress
    copytruncate
    missingok
    size +4096k
    sharedscripts
    postrotate
	/bin/kill -HUP `cat /var/run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true
    endscript
}

logrotate.status

logrotate的状态记录文件,记录上一次日志转储文件的记录状态

[root@ecs-2689 logrotate.d]# cat /var/lib/logrotate/logrotate.status
logrotate state -- version 2
"/var/log/syslog" 2022-3-14-17:0:0
"/var/log/startup.log" 2022-3-14-17:0:0
"/var/log/dnf.librepo.log" 2022-3-14-17:0:0
"/var/log/cloud-init.log" 2022-3-14-17:0:0
"/var/log/firewalld" 2022-3-14-17:0:0
"/var/log/rpmpkgs" 2022-3-20-0:1:1
"/var/log/cloud-init-output.log" 2022-3-14-17:0:0
"/var/log/grubby_prune_debug" 2022-3-14-17:0:0
"/var/log/boot.log" 2022-3-14-17:0:0
"/var/named/data/named.run" 2022-3-14-17:0:0
"/var/log/fd_monitor.log" 2022-3-14-17:0:0
"/var/log/hawkey.log" 2022-3-14-17:0:0
"/var/log/sssd/*.log" 2022-3-14-17:0:0
"/var/log/kern.log" 2022-3-14-17:0:0
"/var/log/chrony/*.log" 2022-3-14-17:0:0
"/var/log/daemon.log" 2022-3-14-17:0:0
"/var/log/wtmp" 2022-3-14-17:0:0
"/var/log/unused.log" 2022-3-14-17:0:0
"/var/log/spooler" 2022-3-14-17:0:0
"/var/log/btmp" 2022-3-14-17:0:0
"/var/log/tuned/*.log" 2022-3-14-17:0:0
"/var/log/maillog" 2022-3-14-17:0:0
"/var/log/installOS/*" 2022-3-14-17:0:0
"/var/log/backup_conf.log" 2022-3-14-17:0:0
"/var/log/secure" 2022-3-25-5:1:2
"/var/log/cron.log" 2022-3-14-17:0:0
"/var/log/rhsm/*.log" 2022-3-14-17:0:0
"/var/log/messages" 2022-3-25-4:1:2
"/var/log/samba/log.*" 2022-3-14-17:0:0
"/var/log/cron" 2022-3-22-20:1:1
"/var/log/osHealthCheck/osHealthCheck.log" 2022-3-14-17:0:0

logrotate参数

参数说明
compress启用压缩,指的是轮替后的旧日志,这里默认用的是gzip压缩的
compressoptions以gzip -9的模式压缩
uncompresscmd解压日志,默认是gunzip
daily每天轮替选项
dateext轮替的日志文件会附加上一个短横线和YYYYMMDD格式的时间戳
delaycompress将以前的日志文件压缩推迟到下一次轮替
ifempty即使日志文件是空的也轮替
mail将轮替后的文件发送到指定E-mail地址
copytruncate用于还在打开中的日志文件,把当前日志备份并截断,开始轮替
mailfirst/maillast向邮件发送轮替文件/轮替后历史文件(默认)
monthly一个月轮替一次
nocompress如果在logrotate.conf中启用了压缩,这里是做不用压缩的参数
nomail不发送邮件到任何地址
ifempty如果日志时空的就不轮替
olddir directory轮替后日志文件放入指定的目录,必须和当前日志文件在同一个文件系统
postrotate/endscript在做完轮替后的命令,两个关键字必须单独成行,使用的操作在2者之间相当于分组“{}”,注意的使用外部指令时要用绝对路径
prerotate/endscript在做轮替前的命令,同上
rotate count轮替最多保留之前的数据几次,超出的将被删除或邮件接收,设为0则不保存
size size当日志增长到指定大小的时候开始轮替,它不会考虑
start count轮替文件名基于这个数字。 例如,指定0时,原日志文件轮替的备份文件以.0为扩展名,如果指定9,就直接从.9开始跳过0-8 然后再继续向后轮替rotate指定的次数。
weekly如果当前的星期几比上次轮替的星期几少,或者过了一个多星期,就会发生轮替通常是在每周的第一天轮替,如果logrotate不是每天运行的,会在第一次有机会时进行轮替。
yearly如果当前年份不同于上次轮替的年份,则进行日志轮替
create mode owner group在轮替动作之后,postrotate脚本执行之前,立即使用刚轮替的日志文件名创建日志文件。 MODE 指定日志文件的权限(0660之类) OWNER 指定日志文件的属主 GROUP 指定日志文件的属组
extension ext日志文件可在轮替后使用指定的EXT扩展名。如果使用压缩,通常EXT后还会加上压缩文件的扩展名,通常是.gz。例如想把mylog.foo轮转为mylog.1.foo.gz而不是mylog.foo.1.gz

logrotate指令

指令全称解释
-d--debugdebug模式,测试配置文件是否有错误。不进行具体操作
-f--force强制转储文件。测试时查看效果
-m--mail==command压缩日志后,发送日志到指定邮箱
-s--state=statefile使用指定的状态文件
-v--verbose显示转储过程

crontab集成logrotate

Logrotate是基于CRON(定时器)来运行的,其脚本是/etc/cron.daily/logrotate,日志轮转是系统自动完成的。 实际运行时,Logrotate会调用配置文件/etc/logrotate.conf。但是这种的配置logrotate只能是每天或者每月进行日志的切割,并不满足大多数的情况,我们可以通过自己配置定时任务来完成日志的转储。

示例

  1. 创建存放logrotate配置文件的目录

[root@ecs-2689 etc]# mkdir /etc/testLogrotate
  1. 创建logrotate配置文件,并写入logrotate配置

[root@ecs-2689 etc]# cat testLogrotate/test
/var/log/test.log {
  size 1k
  rotate 10
  compress
  copytruncate
  missingok
  dateext
  dateformat .%Y_%m_%d_%s
}
  1. 创建日志文件伪造数据设置权限777查看文件大小使其大于文件转储阈值

[root@ecs-2689 log]# chmod 777 test.log
[root@ecs-2689 log]# stat test.log
  File: test.log
  Size: 38583     	Blocks: 80         IO Block: 4096   regular file
Device: fd01h/64769d	Inode: 1051346     Links: 1
Access: (0600/-rw-------)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-03-26 18:03:55.167564243 +0800
Modify: 2022-03-26 18:03:55.167564243 +0800
Change: 2022-03-26 18:03:55.167564243 +0800
 Birth: 2022-03-26 18:03:55.167564243 +0800
  1. 将编辑好的定时任务放到crontab.conf文件里

[root@ecs-2689 log]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed


*/30 * * * * root /usr/sbin/logrotate -s /tmp/agent-logrotate.status /etc/servicestage-agent/agent-logrotate
# 新增的日志转储定时任务,每分钟执行一次转储并且添加状态到agent-logrotate.status
* * * * * root  /usr/sbin/logrotate -s /tmp/agent-logrotate.status /etc/testLogrotate/test
  1. 发现生成一个压缩包,并且原来的日志文件大小为0

[root@ecs-2689 log]# ll |grep  test.log
-rwxrwxrwx  1 root   root         0 Mar 26 18:30 test.log
-rwxrwxrwx  1 root   root       741 Mar 26 18:29 test.log.2022_03_26_1648290601.gz
[root@ecs-2689 log]# stat test.log
  File: test.log
  Size: 0         	Blocks: 0          IO Block: 4096   regular empty file
Device: fd01h/64769d	Inode: 1051346     Links: 1
Access: (0777/-rwxrwxrwx)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2022-03-26 18:30:01.337602000 +0800
Modify: 2022-03-26 18:30:01.341602110 +0800
Change: 2022-03-26 18:30:01.341602110 +0800
 Birth: 2022-03-26 18:03:55.167564243 +0800
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值