编写了一条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 root@k8s-master1.localdomain Fri Mar 3 00:18:05 2023
Return-Path: <root@k8s-master1.localdomain>
X-Original-To: root
Delivered-To: root@k8s-master1.localdomain
Received: by k8s-master1.localdomain (Postfix, from userid 0)
id 187C5AFB0A8; Fri, 3 Mar 2023 00:18:05 +0800 (HKT)
From: "(Cron Daemon)" <root@k8s-master1.localdomain>
To: root@k8s-master1.localdomain
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: <20230302161805.187C5AFB0A8@k8s-master1.localdomain>
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文章来源:https://www.toymoban.com/news/detail-427395.html
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文章来源地址https://www.toymoban.com/news/detail-427395.html
到了这里,关于如何查看Crontab任务是否执行的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!