crontab环境变量问题
今天设置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环境变量问题的更多相关文章
- [转]crontab环境变量设置
原文连接:http://blog.csdn.net/zc02051126/article/details/20480289 come from http://www.360doc.com/conten ...
- [CentOS] 解决 crontab 无法读取环境变量的问题
参考资料:http://blog.slogra.com/post-238.html 1. 问题描述 一段数据处理的 shell 程序,在 shell 中手动运行,可以正确执行.但是,把它放在 cron ...
- Linux中crontab的坑爹环境变量问题
手动在CentOS中执行sh脚本,调用java程序,一切正常: 将该sh加入crontab中定时调度之后,挂了,完全没有执行到的感觉啊!!! 查看crontab执行日志: cat /var/log/c ...
- crontab读取环境变量方法
crontab如果不注意的话早晚会出问题,而且这种问题一旦出一次,就会永远记得,因为这种问题很折腾人. ...
- crontab与环境变量
一个shell脚本,直接执行能成功,但是加在crontab后确怎么也执行不成功. 问题的原因是:crontab的环境变量与直接执行用户的环境变量不一样. export PATH=$PATH:/sbin ...
- crontab 中 python(cx_Oracle)脚本执行时需要用户环境变量,怎么办??
import cx_Oracle Traceback (most recent call last): File "", line 1, in ? ImportError: lib ...
- crontab演出newLISP脚本设置环境变量
今天遇到一个问题.执行在终端newLISP文字,一切正常,搬去crontab在将无法正常工作.即使crontab -e命令是在同一个用户执行.还是有问题. 因为newLISP脚本使用hive和hado ...
- crontab中引入环境变量(比如需要执行tomcat的关闭启动)
起因 crontab中的定时任务,执行到关闭tomcat时,报环境变量找不到 解决方案 1.使用 . /etc/profile 引入环境变量 ###推荐, 实测ubuntu12 成功 2.使用 sou ...
- crontab的两大坑:百分号和环境变量
今天想给服务器加个自动备份mysql数据库的功能(别怪我这么久才加,阿里云每天全盘备份的,不怕丢数据库),本以为只要5分钟就能搞定的,结果入了两个大坑. 我的crontab是这样写的: * * * m ...
随机推荐
- #pragma warning 启用和禁用warning
开发人员可以使用 #pragma 指令将警告作为错误处理:还可以启用或禁用警告,如下面的示例所示: 1.将一个warning作为一个错误 #pragma warning (error: 6260) 2 ...
- android学习日记03--常用控件ListView
常用控件 8.ListView 列表视图,比如游戏的排行榜.列表数据可以根据屏幕大小自适应 列表的显示需要三个元素: a.ListVeiw:用来展示列表的View. b.适配器:用来把数据映射到Lis ...
- com.code.servlet
package com.code.servlet; import java.io.IOException; import java.util.LinkedHashMap; import java.ut ...
- Top 10 Algorithms for Coding Interview--reference
By X Wang Update History:Web Version latest update: 4/6/2014PDF Version latest update: 1/16/2014 The ...
- Android之利用HTTP网络通信实现与PHP的交互(三)
Android与PHP的交互是通过Http网络编程来实现的,利用php访问数据库,并且操作数据库中的数据,利用php作为接口,使Android连接数据库. 一般情况下,我们使用Json格式进行传输,利 ...
- [转]div里table居中的问题 Div与body顶部间隙
本文转自:http://www.cnblogs.com/jinhui/archive/2008/09/24/1297729.html 将div的text-align设为center,然后将table的 ...
- JFace中的表格型树TableTreeViewer
表格型树是用TableTreeViewer来实现,自从SWT下的TableTree被废弃之后,其扩展TableTreeViewer也成了鸡肋,不再被建议使用,既然Tree可以实现表格型树,那么其扩展T ...
- wamp 提示 Directive allow_call_time_pass_reference is no longer avaiable in PHP
在wamp运行时,提示"Directive allow_call_time_pass_reference is no longer avaiable in PHP",点击确定之后, ...
- Atom编辑器入门到精通(六) Markdown支持
尽管我们使用Atom主要是为了编写代码,不过Atom还支持编辑很多其他格式的文件. 比如Markdown和Asciidoc. 这一章中我们主要学习如何快速方便地编辑Markdown文件.另外在写这篇博 ...
- 【转】ArrayList的toArray,也就是list.toArray[new String[list.size()]];,即List转为数组
[转]ArrayList的toArray ArrayList提供了一个将List转为数组的一个非常方便的方法toArray.toArray有两个重载的方法: 1.list.toArray(); 2.l ...