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的命令。

  • 相关阅读:
    Miller_Rabin
    无向图必经点、必经边的相关问题
    无向图的连通性与相关问题
    HNOI2012 矿场搭建 v-DCC缩点+分类讨论
    冗余路径 Redundant Paths e-DCC缩点
    poj1275 Cashier Employment 差分约束
    csp2019游记
    picxivic爬虫
    水贴自动机
    三维生命游戏
  • 原文地址:https://www.cnblogs.com/xzlive/p/13409787.html
Copyright © 2011-2022 走看看