0


如何查看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: <[email protected]>
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)" <[email protected]>
To: [email protected]
Subject: Cron <root@k8s-master1> sh /workspace/tomcat_restart.sh
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
Precedence: bulk
X-Cron-Env: <XDG_SESSION_ID=45>
X-Cron-Env: <XDG_RUNTIME_DIR=/run/user/0>
X-Cron-Env: <LANG=en_US.UTF-8>
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>
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/86572370https://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%82https://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 运维 服务器

本文转载自: https://blog.csdn.net/szuwangjl/article/details/129311728
版权归原作者 szuwangjl 所有, 如有侵权,请联系我们删除。

“如何查看Crontab任务是否执行”的评论:

还没有评论