我自仰头向天笑,笑完我就去睡觉,哈哈哈哈……

bash脚本在crontab自动执行和手动执行得到的结果不一样的问题的处理办法

有时候bash脚本在crontab自动执行的时候,得到的结果和手动执行可能不一样。这种情况,首先可以考虑脚本的执行权限问题。

具体信息,查看日志:

tailf /var/log/cron

如果是这种问题,则重启cron可以解决:

Jun  3 14:01:01 file crond[18438]: (root) FAILED to authorize user with PAM (Module is unknown)
Jun  3 14:01:01 file crond[18436]: (root) FAILED to authorize user with PAM (Module is unknown)

重启:

/etc/init.d/crond restart

 

另外有可能日志信息都是正常的,可以试试在脚本的第二行加入:

source /etc/profile

例如:

#!/bin/bash
source /etc/profile
LANG="en_US.utf8"
export LANG

iptables-save > /root/iptables/_iptables.conf.txt

 

posted @ 2021-06-02 18:07  轻轻的烟雾  阅读(596)  评论(0编辑  收藏  举报