CentOS 7 crontab 不执行

报错 /bin/sh: root: command not found

解决: 检查文件( /var/spool/cron/root )及脚本(xxx.sh)是否正确

 

文件 /etc/crontab 全部内容

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed

12 * * * * rm -rf /tmp/tmp* &


#12 * * * * sh /root/script/kill_firefox.sh

#05 */2 * * * cd /root/script/ && ./proxy_server.sh
06 22 * * * cd /root/script/ && ./proxy_server.sh

 

查看crontab 状态

service crond status

[root@mimvp_usa ~]# service crond status
● crond.service - Command Scheduler
   Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2016-06-12 22:22:23 CST; 11min ago
 Main PID: 488 (crond)
   CGroup: /system.slice/crond.service
           └─488 /usr/sbin/crond -n

Jun 12 22:22:23 mimvp_usa systemd[1]: Started Command Scheduler.
Jun 12 22:22:23 mimvp_usa systemd[1]: Starting Command Scheduler...
Jun 12 22:22:23 mimvp_usa crond[488]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 75% if used.)
Jun 12 22:22:23 mimvp_usa crond[488]: (CRON) INFO (running with inotify support)
Jun 12 22:23:01 mimvp_usa crond[488]: (root) RELOAD (/var/spool/cron/root)
Jun 12 22:25:01 mimvp_usa crond[488]: (root) RELOAD (/var/spool/cron/root)

 

postfix 报错

出错信息:postfix: fatal: parameter inet_interfaces: no local interface found for ::1

解决1:断定IPv6在作怪,想起/etc/hosts文件里的IPV6的设定,决定注释掉。

#::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

再次启动Postfix(或重启服务器 reboot),正常启动。

systemctl start postfix.service

systemctl status postfix.service

[root@mimvp_usa ~]# systemctl start postfix.service
[root@mimvp_usa ~]# systemctl status postfix.service
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; disabled; vendor preset: disabled)
   Active: active (running) since Sun 2016-06-12 22:37:26 CST; 9s ago
  Process: 14944 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)
  Process: 14940 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
  Process: 14937 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS)
 Main PID: 15089 (master)
   CGroup: /system.slice/postfix.service
           ├─15089 /usr/libexec/postfix/master -w
           ├─15091 pickup -l -t unix -u
           └─15092 qmgr -l -t unix -u

Jun 12 22:37:22 mimvp_usa systemd[1]: Starting Postfix Mail Transport Agent...
Jun 12 22:37:25 mimvp_usa postfix/postfix-script[15083]: starting the Postfix mail system
Jun 12 22:37:26 mimvp_usa postfix/master[15089]: daemon started -- version 2.10.1, configuration /etc/postfix
Jun 12 22:37:26 mimvp_usa systemd[1]: Started Postfix Mail Transport Agent.

 

解决2:

service postfix start总是FAILED. 最后没办法

vim /etc/postfix/main.cf

发现配置为:

inet_interfaces = localhost

inet_protocols = all

改成:

inet_interfaces = 127.0.0.1  #只能接受内部邮件,其它邮件不接受

inet_protocols = all

然后重启服务就好了,特此记录!

 

测试发送邮件:

mail -s "hello  mimvp"  yanggang@mimvp.com

 

参考推荐:

centos(7.0) 上 crontab 计划任务