ITPub博客

首页 > Linux操作系统 > Linux操作系统 > crontab调度Python脚本

crontab调度Python脚本

原创 Linux操作系统 作者:std1984 时间:2013-03-22 16:16:51 0 删除 编辑
环境:Red Hat Enterprise Linux Server release 5.4 (Tikanga),  python 2.7
 
 
由于本人对shell脚本语法相当不喜欢,一般与操作系统打交道用python脚本。在用crontab调度python脚有两个地方要注意:
 
1.  在python脚本中增加#!/usr/bin/env python来声明执行程序在系统环境变量中的名字
 
2.  在crontab中增加. $HOME/.bash_profile来调用bash_profile来声明环境变量,例: 19 16 * * * . $HOME/.bash_profile;/home/oradev/wget_test.py
 
 
注:  文件wget_test.py为可执行状态 -- chmod +x wget_test.py
        该文件的目录必须在环境变量PATH 内。
 
还遇到一问题就是脚本不执行也不报错,最终发现python有两个版本,一个版本在/usr/bin/python是2.4.3,将其删除并指定软链接 ln -s /usr/local/bin/python2.7 /usr/bin/python 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/16582684/viewspace-756872/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-12-29

  • 博文量
    171
  • 访问量
    1401344