V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
phpfpm
V2EX  ›  CentOS

为什么 CENTOS crontab 的 PATH 不包含/usr/sbin?

  •  
  •   phpfpm · 102 天前 · 522 次点击
    这是一个创建于 102 天前的主题,其中的信息可能已经有所发展或是发生改变。

    遇到的问题

    研发侧发现,一个 php 脚本可以正常调用docker(podman)进行一些操作,但是经由 crontab 调度则执行失败

    只说重点

    1. 发行版:腾讯云的 TencentOS Server 3.1 (TK4)
    2. 登录的 shell 的 PATH 有 /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin
    3. crontab 的 path 只有/usr/bin:/bin
    4. 如果缺乏/usr/sbin 会导致 podman 启动的时候无法访问到/usr/sbin/iptables

    我想知道的问题

    1. crontab 的 path 没有/usr/sbin到底是为啥
    2. 在 crontab 调度 docker 启动一个临时容器做一些事情的时候,正确的姿势是什么?手动指定一下 path?
    3 条回复    2024-01-16 12:03:53 +08:00
    L4Linux
        1
    L4Linux  
       102 天前 via Android   ❤️ 1
    现在的趋势是 /bin /sbin /usr/bin /usr/sbin 四合一。可能发行版开发者都认为没必要了。
    lululau
        2
    lululau  
       102 天前   ❤️ 1
    crontab 标准写法:

    /bin/bash -l -c 'your commands'
    julyclyde
        3
    julyclyde  
       102 天前
    man crond
    PAM Access Control
    Cron supports access control with PAM if the system has PAM installed.
    For more information, see pam(8). A PAM configuration file for crond
    is installed in /etc/pam.d/crond. The daemon loads the PAM environment
    from the pam_env module. This can be overridden by defining specific
    settings in the appropriate crontab file.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2885 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 07:44 · PVG 15:44 · LAX 00:44 · JFK 03:44
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.