crontab(centos 7)自动调度一直无法正常执行,解决方案

一、背景

crontab基本命令介绍:

crontab -e :编辑crontab定时任务

crontab -l :查看crontab定时任务里面所有的任务

二、解决思路

首先查看crontab 日志

cat /var/log/cron

Jul 27 02:00:01 iZ88bfrkh86Z CROND[16210]: (aaron) MAIL (mailed 43 bytes of output but got status 0x004b

)

出现如上错误信息,怀疑是因为crontab出现问题。

接着继续命令查看crontab运行状态信息

[root@iZ88bfrkh86Z mail]# service crond status

Redirecting to /bin/systemctl status crond.service

crond.service - Command Scheduler

Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled)

Active: active (running) since Fri 2017-06-02 16:55:02 CST; 1 months 24 days ago

Main PID: 770 (crond)

CGroup: /system.slice/crond.service

└─770 /usr/sbin/crond -n

Jul 27 10:27:01 iZ88bfrkh86Z crond[770]: sendmail: fatal: parameter inet_interfaces: no local interface found for ::1

可以看出是mail出了问题

vi  /etc/postfix/main.cf

发现配置为:

inet_interfaces = localhost

inet_protocols = all

改成:

inet_interfaces = all

inet_protocols = all

重新启动

service postfix start

再次查看crontab运行状态信息

[root@iZ88bfrkh86Z mail]# service crond status

Redirecting to /bin/systemctl status crond.service

crond.service - Command Scheduler

Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled)

Active: active (running) since Fri 2017-06-02 16:55:02 CST; 1 months 24 days ago

Main PID: 770 (crond)

CGroup: /system.slice/crond.service

└─770 /usr/sbin/crond -n

Jul 27 10:27:01 iZ88bfrkh86Z crond[770]: sendmail: fatal: parameter inet_interfaces: no local interface found for ::1

Jul 27 11:04:42 iZ88bfrkh86Z systemd[1]: Started Command Scheduler.

再次调用crontab,查看运行日志

[aaron@iZ88bfrkh86Z ~]$ cat /var/spool/mail/aaron

From aaron@iZ88bfrkh86Z.localdomain Thu Jul 27 11:12:01 2017

Return-Path:

X-Original-To: aaron

Delivered-To: aaron@iZ88bfrkh86Z.localdomain

Received: by iZ88bfrkh86Z.localdomain (Postfix, from userid 1000)

id 26D6480FDD; Thu, 27 Jul 2017 11:12:01 +0800 (CST)

From: "(Cron Daemon)"

To: aaron@iZ88bfrkh86Z.localdomain

Subject: Cron sh /home/aaron/auto.sh >/home/aaron/log

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:

Date: Thu, 27 Jul 2017 11:12:01 +0800 (CST)

/home/aaron/auto.sh: line 3: java: command not found

发现错误是因为java环境变量配置引起的

故需要在自己的shell脚本里加入一行代码

source /etc/profile

再次调用crontab ,运行成功

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值