zoukankan      html  css  js  c++  java
  • linux配置定时任务的用户环境变量

    在Linux系统中,执行定时任务时,默认加载的是用户环境变量 ~/.bashrc ,不会加载系统变量,而要使用系统变量,可以用如下方式:

    # 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
    
    */1  *  *  *  * root /root/xx.sh                           # 使用用户环境变量
    */1  *  *  *  * root source ~/.bashrc &&  /root/xx.sh      # 使用用户环境变量
    
    */1  *  *  *  * root source /etc/profile &&  /root/xx.sh   # 使用系统环境变量

      在以上的配置中,定时任务只是默认加载当前用户的环境变量,即 所有的定时任务,默认使用 source ~/.bashrc 来加载执行后续命令的。

      如果要加载 系统环境变量,则需指定加载系统变量文件,即 source /etc/profile 这段命令。 && 符号意思就是执行多个命令,这里是先加载系统环境变量,然后再执行 /root/xx.sh的命令。

  • 相关阅读:
    PowerDesigner中Table视图同时显示Code和Name
    sql语句 生成数据库表
    业务流程图
    物理模型图-数据库图
    观察者模式
    UML的九种图
    路由器工作原理
    web项目中处理捕获异常统一处理
    java中volatile、synchronized
    linux 安装软件的几种方法
  • 原文地址:https://www.cnblogs.com/xzlive/p/13409787.html
Copyright © 2011-2022 走看看