今天设置linux定时任务时,python内调用的shell指令总执行失败,单独调用python脚本则无问题,考虑到是环境变量未生效引起。

故在执行crontab -e编辑配置文件时,将shell内执行env指令得到的环境变量(PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games)加入到任务(31 15 * * *  python /opt/ybs/bin/backup.py  >> /opt/ybs/log/backup.log 2>&1)之前。

编辑后的文件如下:

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
31 15 * * * python /opt/ybs/bin/backup.py >> /opt/ybs/log/backup.log 2>&1

保存退出。

实测成功执行。

crontab环境变量问题的更多相关文章

  1. [转]crontab环境变量设置

    原文连接:http://blog.csdn.net/zc02051126/article/details/20480289 come from http://www.360doc.com/conten ...

  2. [CentOS] 解决 crontab 无法读取环境变量的问题

    参考资料:http://blog.slogra.com/post-238.html 1. 问题描述 一段数据处理的 shell 程序,在 shell 中手动运行,可以正确执行.但是,把它放在 cron ...

  3. Linux中crontab的坑爹环境变量问题

    手动在CentOS中执行sh脚本,调用java程序,一切正常: 将该sh加入crontab中定时调度之后,挂了,完全没有执行到的感觉啊!!! 查看crontab执行日志: cat /var/log/c ...

  4. crontab读取环境变量方法

    crontab如果不注意的话早晚会出问题,而且这种问题一旦出一次,就会永远记得,因为这种问题很折腾人.                                                  ...

  5. crontab与环境变量

    一个shell脚本,直接执行能成功,但是加在crontab后确怎么也执行不成功. 问题的原因是:crontab的环境变量与直接执行用户的环境变量不一样. export PATH=$PATH:/sbin ...

  6. crontab 中 python(cx_Oracle)脚本执行时需要用户环境变量,怎么办??

    import cx_Oracle Traceback (most recent call last): File "", line 1, in ? ImportError: lib ...

  7. crontab演出newLISP脚本设置环境变量

    今天遇到一个问题.执行在终端newLISP文字,一切正常,搬去crontab在将无法正常工作.即使crontab -e命令是在同一个用户执行.还是有问题. 因为newLISP脚本使用hive和hado ...

  8. crontab中引入环境变量(比如需要执行tomcat的关闭启动)

    起因 crontab中的定时任务,执行到关闭tomcat时,报环境变量找不到 解决方案 1.使用 . /etc/profile 引入环境变量 ###推荐, 实测ubuntu12 成功 2.使用 sou ...

  9. crontab的两大坑:百分号和环境变量

    今天想给服务器加个自动备份mysql数据库的功能(别怪我这么久才加,阿里云每天全盘备份的,不怕丢数据库),本以为只要5分钟就能搞定的,结果入了两个大坑. 我的crontab是这样写的: * * * m ...

随机推荐

  1. 给postfix设置黑名单

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  2. HDU 5289 Assignment(2015 多校第一场二分 + RMQ)

    Assignment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  3. hdu 5459 Jesus Is Here 数学

    Jesus Is Here Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid= ...

  4. 7Zip 来备份重要文件(夹)

    body { font-family: 宋体,Georgia,Helvetica,Arial,sans-serif,宋体,serif; font-size: 10.5pt; line-height: ...

  5. poj 1147 Binary codes

    Binary codes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5647   Accepted: 2201 Desc ...

  6. 03---JavaScript基础整理

    一.概述:           Netscape开发的一种基于对象和事件驱动的脚本语言.                  被设计用来想HTML页面添加交互行为.           无需编译,可由浏 ...

  7. Yum本地Rpm库设置

    http://blog.csdn.net/dc_726/article/details/8497188   1 Yum对光盘的支持 查看/etc/yum.repos.d/CentOS-Media.re ...

  8. PAT 1016

    1016. Phone Bills (25) A long-distance telephone company charges its customers by the following rule ...

  9. java中public等权限问题和final的使用

    1.public:public表明该数据成员.成员函数是对所有用户开放的,所有用户都可以直接进行调用 2.private:private表示私有,私有的意思就是除了class自己之外,任何人都不可以直 ...

  10. 使用AndroidScreenSlidePager开源库

    一.下载地址 https://github.com/LyndonChin/AndroidScreenSlidePager 点击右侧的Download ZIp按钮进行下载.然后解压缩到本地. 二.使用方 ...