机器重启 查看crontab执行历史记录crontab没有执行

摘要:
这需要查看crontab的执行历史。具体位置如下:cd/var/logtail-100cron可以查看cron文件中已操作的相关计划任务。


Sep 17 19:01:01 d run-parts(/etc/cron.hourly)[8452]: finished 0anacron
Sep 17 19:10:01 d CROND[9059]: (root) CMD (cd /root/tools/trunk/plugins/personas; python sync_db.py &> /dev/null)
Sep 17 19:10:01 d CROND[9060]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Sep 17 19:20:01 d CROND[9736]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Sep 17 19:20:01 d CROND[9737]: (root) CMD (cd /root/tools/trunk/plugins/personas; python sync_db.py &> /dev/null)
Sep 17 19:30:01 d CROND[10411]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Sep 17 19:30:01 d CROND[10412]: (root) CMD (cd /root/tools/trunk/plugins/personas; python sync_db.py &> /dev/null)
Sep 17 19:32:10 d crontab[10571]: (root) LIST (root)
Sep 17 19:40:01 d CROND[11086]: (root) CMD (cd /root/tools/trunk/plugins/personas; python sync_db.py &> /dev/null)
Sep 17 19:40:01 d CROND[11087]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Sep 17 19:50:01 d CROND[11762]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Sep 17 19:50:01 d CROND[11763]: (root) CMD (cd /root/tools/trunk/plugins/personas; python sync_db.py &> /dev/null)
Sep 20 12:40:02 d crontab[582]: (root) LIST (root)
Sep 20 13:36:43 d crontab[4633]: (root) LIST (root)
Sep 20 14:46:11 d crontab[9954]: (root) LIST (root)
[root@d log]# tail -100 /var/log/cron

CentOS下查看crontab执行历史记录 - Jerry.Kwan - 博客园 https://www.cnblogs.com/Jerryshome/archive/2012/02/16/2353537.html

在crontab中添加了定时任务,但发现没有得到期望的结果,因而怀疑是crontab没有执行相应的任务,但怎么定位crontab是否执行呢?
这就需要查看crontab的执行历史记录,具体位置如下:
cd /var/log
tail -100 cron
在cron文件中即可查阅已经操作过的相关定时任务。

查看定时脚本目录

[root@d log]# ll -as /var/spool/
total 52
4 drwxr-xr-x. 13 root root 4096 Sep 14 23:24 .
4 drwxr-xr-x. 23 root root 4096 Sep 14 23:23 ..
4 drwxr-x--x 2 root abrt 4096 Apr 27 22:53 abrt
4 drwx------. 2 abrt abrt 4096 Apr 27 22:53 abrt-upload
4 drwxr-xr-x. 2 root root 4096 Apr 11 09:48 anacron
4 drwx------. 3 root root 4096 Apr 11 08:13 at
4 drwx------. 2 root root 4096 Apr 11 09:48 cron
4 drwx--x---. 3 root lp 4096 Apr 11 13:03 cups
4 drwxr-xr-x. 2 root root 4096 Apr 11 12:59 lpd
4 drwxrwxr-x. 2 root mail 4096 Apr 11 12:59 mail
4 drwxr-xr-x. 2 root root 4096 Apr 13 20:53 plymouth
4 drwxr-xr-x. 16 root root 4096 Nov 21 2014 postfix
4 drwxrwxrwt 2 root root 4096 Jan 18 2017 samba
[root@d log]# ll -as /var/spool/cron/
total 12
4 drwx------. 2 root root 4096 Apr 11 09:48 .
4 drwxr-xr-x. 13 root root 4096 Sep 14 23:24 ..
4 -rw------- 1 root root 398 Jun 7 09:05 root
[root@d log]# cat /var/spool/cron/root
# create by root at 2017/10/20
*/10 * * * * cd /root/tools/trunk/plugins/personas; python sync_db.py &> /dev/null

# create by root at 2017/10/27
00 02 * * * cd /root/tools/trunk/plugins/personas; python sync_db_full.py &> /dev/null


[root@d log]#

机器重启 查看crontab执行历史记录crontab没有执行第1张


[root@d log]# systemctl list-unit-files --type=service > tmpDEL
[root@d log]# cat tmpDEL
UNIT FILE STATE
abrt-ccpp.service disabled
abrt-oops.service disabled
abrt-pstoreoops.service disabled
abrt-vmcore.service disabled
abrt-xorg.service disabled
abrtd.service disabled
aliyun.service disabled
arp-ethers.service disabled
atd.service disabled
auditd.service disabled
auth-rpcgss-module.service static
autovt@.service enabled
avahi-daemon.service disabled
blk-availability.service disabled
brandbot.service static
chrony-wait.service disabled
chronyd.service disabled
console-getty.service disabled
console-shell.service disabled
container-getty@.service static
cpupower.service disabled
crond.service enabled
cups-browsed.service disabled
cups.service enabled
dbus-org.freedesktop.hostname1.service static
dbus-org.freedesktop.import1.service static
dbus-org.freedesktop.locale1.service static
dbus-org.freedesktop.login1.service static
dbus-org.freedesktop.machine1.service static
dbus-org.freedesktop.timedate1.service static
dbus.service static
debug-shell.service disabled
dm-event.service static
dmraid-activation.service enabled
dnsmasq.service disabled
dracut-cmdline.service static
dracut-initqueue.service static
dracut-mount.service static
dracut-pre-mount.service static
dracut-pre-pivot.service static
dracut-pre-trigger.service static
dracut-pre-udev.service static
dracut-shutdown.service static
ebtables.service disabled
emergency.service static
firewalld.service disabled
fprintd.service static
fstrim.service static
getty@.service enabled
gssproxy.service disabled
halt-local.service static
initrd-cleanup.service static
initrd-parse-etc.service static
initrd-switch-root.service static
initrd-udevadm-cleanup-db.service static
irqbalance.service disabled
kdump.service disabled
kmod-static-nodes.service static
libstoragemgmt.service disabled
lvm2-lvmetad.service disabled
lvm2-lvmpolld.service disabled
lvm2-monitor.service enabled
lvm2-pvscan@.service static
mdmon@.service static
mdmonitor.service disabled
messagebus.service static
microcode.service enabled
NetworkManager-dispatcher.service disabled
NetworkManager-wait-online.service enabled
NetworkManager.service disabled
nfs-blkmap.service disabled
nfs-config.service static
nfs-idmap.service static
nfs-idmapd.service static
nfs-lock.service static
nfs-mountd.service static
nfs-rquotad.service disabled
nfs-secure.service static
nfs-server.service disabled
nfs-utils.service static
nfs.service disabled
nfslock.service static
nmb.service disabled
nscd.service enabled
ntpd.service enabled
ntpdate.service disabled
plymouth-halt.service disabled
plymouth-kexec.service disabled
plymouth-poweroff.service disabled
plymouth-quit-wait.service disabled
plymouth-quit.service disabled
plymouth-read-write.service disabled
plymouth-reboot.service disabled
plymouth-start.service disabled
plymouth-switch-root.service static
polkit.service static
postfix.service disabled
psacct.service disabled
quotaon.service static
rc-local.service static
rdisc.service disabled
rdma-load-modules@.service static
rdma-ndd.service static
rdma.service disabled
redis-sentinel.service disabled
redis.service disabled
rescue.service static
rhel-autorelabel-mark.service enabled
rhel-autorelabel.service enabled
rhel-configure.service enabled
rhel-dmesg.service enabled
rhel-domainname.service enabled
rhel-import-state.service enabled
rhel-loadmodules.service enabled
rhel-readonly.service enabled
rngd.service disabled
rpc-gssd.service static
rpc-rquotad.service disabled
rpc-statd-notify.service static
rpc-statd.service static
rpcbind.service disabled
rpcgssd.service static
rpcidmapd.service static
rsyncd.service disabled
rsyncd@.service static
rsyslog.service enabled
serial-getty@.service disabled
smartd.service disabled
smb.service disabled
sshd-keygen.service static
sshd.service enabled
sshd@.service static
svnserve.service disabled
sysstat.service enabled
systemd-ask-password-console.service static
systemd-ask-password-plymouth.service static
systemd-ask-password-wall.service static
systemd-backlight@.service static
systemd-binfmt.service static
systemd-bootchart.service disabled
systemd-firstboot.service static
systemd-fsck-root.service static
systemd-fsck@.service static
systemd-halt.service static
systemd-hibernate-resume@.service static
systemd-hibernate.service static
systemd-hostnamed.service static
systemd-hwdb-update.service static
systemd-hybrid-sleep.service static
systemd-importd.service static
systemd-initctl.service static
systemd-journal-catalog-update.service static
systemd-journal-flush.service static
systemd-journald.service static
systemd-kexec.service static
systemd-localed.service static
systemd-logind.service static
systemd-machine-id-commit.service static
systemd-machined.service static
systemd-modules-load.service static
systemd-nspawn@.service disabled
systemd-poweroff.service static
systemd-quotacheck.service static
systemd-random-seed.service static
systemd-readahead-collect.service enabled
systemd-readahead-done.service indirect
systemd-readahead-drop.service enabled
systemd-readahead-replay.service enabled
systemd-reboot.service static
systemd-remount-fs.service static
systemd-rfkill@.service static
systemd-shutdownd.service static
systemd-suspend.service static
systemd-sysctl.service static
systemd-timedated.service static
systemd-tmpfiles-clean.service static
systemd-tmpfiles-setup-dev.service static
systemd-tmpfiles-setup.service static
systemd-udev-settle.service static
systemd-udev-trigger.service static
systemd-udevd.service static
systemd-update-done.service static
systemd-update-utmp-runlevel.service static
systemd-update-utmp.service static
systemd-user-sessions.service static
systemd-vconsole-setup.service static
tcsd.service disabled
teamd@.service static
tuned.service disabled
usb_modeswitch@.service static
wpa_supplicant.service disabled

191 unit files listed.

【开机启动 != 启动成功】

[root@d log]# service crond status
Redirecting to /bin/systemctl status crond.service
● crond.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
Active: failed (Result: signal) since Mon 2018-09-17 19:55:43 CST; 2 days ago
Main PID: 562 (code=killed, signal=KILL)

Sep 17 19:30:01 d crond[10409]: pam_limits(crond:session): invalid line 'soft nofile 95535' - skipped
Sep 17 19:30:01 d crond[10409]: pam_limits(crond:session): invalid line 'hard nofile 95535' - skipped
Sep 17 19:40:01 d crond[11085]: pam_limits(crond:session): invalid line 'soft nofile 95535' - skipped
Sep 17 19:40:01 d crond[11085]: pam_limits(crond:session): invalid line 'hard nofile 95535' - skipped
Sep 17 19:40:01 d crond[11084]: pam_limits(crond:session): invalid line 'soft nofile 95535' - skipped
Sep 17 19:40:01 d crond[11084]: pam_limits(crond:session): invalid line 'hard nofile 95535' - skipped
Sep 17 19:50:01 d crond[11760]: pam_limits(crond:session): invalid line 'soft nofile 95535' - skipped
Sep 17 19:50:01 d crond[11760]: pam_limits(crond:session): invalid line 'hard nofile 95535' - skipped
Sep 17 19:50:01 d crond[11761]: pam_limits(crond:session): invalid line 'soft nofile 95535' - skipped
Sep 17 19:50:01 d crond[11761]: pam_limits(crond:session): invalid line 'hard nofile 95535' - skipped
[root@d log]#

原因为最大文件数配置错误

/etc/security/limits.conf

启动crond和检测状态

[root@d ~]# service crond status -l
Redirecting to /bin/systemctl status -l crond.service
● crond.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Thu 2018-09-20 15:43:30 CST; 2min 14s ago
Process: 14736 ExecStart=/usr/sbin/crond -n $CRONDARGS (code=exited, status=1/FAILURE)
Main PID: 14736 (code=exited, status=1/FAILURE)

Sep 20 15:43:30 d systemd[1]: Started Command Scheduler.
Sep 20 15:43:30 d systemd[1]: Starting Command Scheduler...
Sep 20 15:43:30 d crond[14736]: crond: can't lock /var/run/crond.pid, otherpid may be 12554: Resource temporarily unavailable
Sep 20 15:43:30 d systemd[1]: crond.service: main process exited, code=exited, status=1/FAILURE
Sep 20 15:43:30 d systemd[1]: Unit crond.service entered failed state.
Sep 20 15:43:30 d systemd[1]: crond.service failed.
[root@d ~]# service crond start
Redirecting to /bin/systemctl start crond.service
[root@d ~]# service crond status -l
Redirecting to /bin/systemctl status -l crond.service
● crond.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2018-09-20 15:46:01 CST; 7s ago
Main PID: 15049 (crond)
CGroup: /system.slice/crond.service
└─15049 /usr/sbin/crond -n

Sep 20 15:46:01 d systemd[1]: Started Command Scheduler.
Sep 20 15:46:01 d systemd[1]: Starting Command Scheduler...
Sep 20 15:46:01 d crond[15049]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 80% if used.)
Sep 20 15:46:01 d crond[15049]: (CRON) INFO (running with inotify support)
Sep 20 15:46:01 d crond[15049]: (CRON) INFO (@reboot jobs will be run at computer's startup.)
[root@d ~]#

免责声明:文章转载自《机器重启 查看crontab执行历史记录crontab没有执行》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇python的socketelement-UI el-table样式(去边框和滚动条样式)下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

WSL2 配置及ubuntu18.04安装mysql8.0+

wsl2 完整配置 参考将WSL2作为生产力工具 Installing, this may take a few minutes… WslRegisterDistribution failed with error: 0x800701bc Error: 0x800701bc WSL 2 ??? https://aka.ms/wsl2kernel Pres...

生成CPIO格式的initrd

因为initrd.img只是系统启动的一个虚拟磁盘而已,系统启动完成后就没有用处了,因此,我决定用busybox来完成一些必要的启动工作(用的是busybox-1.5.1,配置文件如下) cd /tmp mkdir initrd cd initrd mkdir dev proc sys lib mnt mkdir -p lib/modules/kernel...

MySQL-跳过主从复制环境中错误

简述 mysql在主从复制过程中,由于各种的原因,从库可能会遇到执行BINLOG中的SQL出错的情况,在默认情况下,将停止复制进程,不再进行同步,等到人工干预来处理。 slave-skip-errors slave-skip-errors的作用就是用来定义复制过程中从库可以自动跳过的错误号,当复制过程中遇到定义的错误号,就可以自动跳过,直接执行后面的SQL...

Linux系统的相关知识、常用命令及拓展、centos 7网卡配置

(本文仅为平时学习记录,若有错误请大佬指出,如果本文能帮到你那我也是很开心啦)   一、Linux系统的相关知识 1.Linux中根目录下所有文件夹的含义和用途 目录 功能 /bin 存放可执行文件 /dev 存放设备文件 (如:网卡、CPU) /media 存放可移除设备文件 (如:U盘、CD/DVD、VMTools) /opt 存放...

Bash数组-判断某个元素是否在数组内的几种方法

声明一个数组array,一个待测试元素var array=( element1 element2 element3 ) var="element1" 接下来用几种方法来分别测试var是否是array中的元素 判断方法1: echo "${array[@]}" | grep -wq "$var" && echo "Yes" || ech...

Kafka集群搭建及安全机制手册

Mycat+Mysql的读写分离 前言: 在MySQL中间件出现之前,对于MySQL主从集群,如果要实现其读写分离,一般是在程序端实现,这样就带来一个问题,即数据库和程序的耦合度太高,如果我数据库的地址发生改变了,那么我程序端也要进行相应的修改,如果数据库不小心挂掉了,则同时也意味着程序的不可用,而这对很多应用来说,并不能接受。 在这里,我用三个实例组成M...