如何查看Crontab任务是否执行

编写了一条crontab如下:

18 * * * * sh /workspace/tomcat_restart.sh

可以通过以下两种方式查看是否任务已经执行。

1、通过/var/log/cron文件查看。

[root@k8s-master1 workspace]# tail -n 5 /var/log/cron
Mar  3 00:17:47 k8s-master1 crontab[20210]: (root) BEGIN EDIT (root)
Mar  3 00:17:50 k8s-master1 crontab[20210]: (root) REPLACE (root)
Mar  3 00:17:50 k8s-master1 crontab[20210]: (root) END EDIT (root)
Mar  3 00:18:01 k8s-master1 crond[768]: (root) RELOAD (/var/spool/cron/root)
Mar  3 00:18:02 k8s-master1 CROND[20213]: (root) CMD (sh /workspace/tomcat_restart.sh)

可以看到最后一行,已经执行。

2、通过/var/spool/cron/root的邮件通知进行查看。

From [email protected]  Fri Mar  3 00:18:05 2023
Return-Path: 
X-Original-To: root
Delivered-To: [email protected]
Received: by k8s-master1.localdomain (Postfix, from userid 0)
        id 187C5AFB0A8; Fri,  3 Mar 2023 00:18:05 +0800 (HKT)
From: "(Cron Daemon)" 
To: [email protected]
Subject: Cron  sh /workspace/tomcat_restart.sh
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
Precedence: bulk
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
X-Cron-Env: 
Message-Id: <[email protected]>
Date: Fri,  3 Mar 2023 00:18:05 +0800 (HKT)

Tomcat started.

可以看到邮件通知(Cron Daemon)已经执行了。

参考文档:

1、https://blog.csdn.net/liaoyanyunde/article/details/86572370icon-default.png?t=N176https://blog.csdn.net/liaoyanyunde/article/details/86572370

2、https://www.cnblogs.com/doseoer/p/5663187.html#:~:text=%E5%9C%A8%20%2Fvar%2Fspool%2Fmail%2Froot%20%E6%96%87%E4%BB%B6%E4%B8%AD%EF%BC%8C%E6%9C%89crontab%E6%89%A7%E8%A1%8C%E6%97%A5%E5%BF%97%E7%9A%84%E8%AE%B0%E5%BD%95%EF%BC%8C%E7%94%A8tail,-f%20%2Fvar%2Fspool%2Fmail%2Froot%20%E5%8D%B3%E5%8F%AF%E6%9F%A5%E7%9C%8B%E6%9C%80%E8%BF%91%E7%9A%84crontab%E6%89%A7%E8%A1%8C%E6%83%85%E5%86%B5%E3%80%82icon-default.png?t=N176https://www.cnblogs.com/doseoer/p/5663187.html#:~:text=%E5%9C%A8%20%2Fvar%2Fspool%2Fmail%2Froot%20%E6%96%87%E4%BB%B6%E4%B8%AD%EF%BC%8C%E6%9C%89crontab%E6%89%A7%E8%A1%8C%E6%97%A5%E5%BF%97%E7%9A%84%E8%AE%B0%E5%BD%95%EF%BC%8C%E7%94%A8tail,-f%20%2Fvar%2Fspool%2Fmail%2Froot%20%E5%8D%B3%E5%8F%AF%E6%9F%A5%E7%9C%8B%E6%9C%80%E8%BF%91%E7%9A%84crontab%E6%89%A7%E8%A1%8C%E6%83%85%E5%86%B5%E3%80%82

你可能感兴趣的:(linux,运维,服务器)