V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
s609926202
V2EX  ›  Linux

Linux 定时任务日志有记录,实际未执行,什么情况?

  •  
  •   s609926202 ·
    shangdev · 2021-09-15 15:25:24 +08:00 · 1316 次点击
    这是一个创建于 925 天前的主题,其中的信息可能已经有所发展或是发生改变。

    日志记录如下:

    Sep 15 15:19:01 VM-16-17-centos CROND[831690]: (root) CMD (/data/wwwroot/scripts/cron.sh 100200  > /dev/null 2>&1)
    Sep 15 15:19:01 VM-16-17-centos CROND[831689]: (root) CMD (/data/wwwroot/scripts/cron.sh 300 > /dev/null 2>&1)
    

    其中 /data/wwwroot/scripts/cron.sh 100200 > /dev/null 2>$1 这一条没有执行。

    初步怀疑是脚本有问题,遂单独在命令行执行 /data/wwwroot/scripts/cron.sh 100200 > /dev/null 2>$1,可以正常执行,说明脚本没问题。

    那应该是 crontab 本身的问题?由于同一时间 15:19:01 连续请求 2 次请求,造成冲突导致的?

    求解、

    第 1 条附言  ·  2021-09-15 16:01:28 +08:00
    智障了,把 /dev/null 2>&1 写成 /dev/null 2>$1 了
    7 条回复    2021-09-15 16:00:53 +08:00
    lcdtyph
        1
    lcdtyph  
       2021-09-15 15:29:14 +08:00 via iPhone
    别重定向到 /dev/null,重定向到文件看看有啥输出呗
    s609926202
        2
    s609926202  
    OP
       2021-09-15 15:30:43 +08:00
    脚本是这样写的:
    ```
    #!/bin/bash

    if [ "$1" -eq 100200 ]; then
    curl 'xxx'
    elif [ "$1" -eq 300 ]; then
    curl 'xxx'
    fi
    ```

    定时器规则:
    ```
    15 10 1 * * /data/wwwroot/scripts/cron.sh 300 > /dev/null 2>$1 &
    19 15 * * 3 /data/wwwroot/scripts/cron.sh 100200 > /dev/null 2>$1 &
    ```
    s609926202
        3
    s609926202  
    OP
       2021-09-15 15:34:23 +08:00
    @lcdtyph 重定向到新建的 log.txt 反而成功了
    ddrobot
        4
    ddrobot  
       2021-09-15 15:45:17 +08:00
    不是 /dev/null 2>&1 吗?
    MartinWu
        5
    MartinWu  
       2021-09-15 15:45:59 +08:00
    @s609926202 是你命令就写错了。 是&1 不是 $1
    s609926202
        6
    s609926202  
    OP
       2021-09-15 15:58:47 +08:00
    @ddrobot 是的
    s609926202
        7
    s609926202  
    OP
       2021-09-15 16:00:53 +08:00
    @MartinWu 还真是写错了、、
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3330 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 13:28 · PVG 21:28 · LAX 06:28 · JFK 09:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.