热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

Sep1719:01:01drun-parts(etccron.hourly)[8452]:finished0anacronSep1719:10:01dCROND[

 

 


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]#

 

 

 

 


[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 ~]#

 


推荐阅读
author-avatar
zg18156zg你
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有