V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
powersee
V2EX  ›  问与答

如何将定时任务 crontab 的输出内容,发送到 server 酱?

  •  
  •   powersee · 2019-04-17 23:02:16 +08:00 · 1637 次点击
    这是一个创建于 1806 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我放置了一些脚本,每天运行,并且写入到 run.log 里面,我想把每天写入 log 时,同时发送到 server 酱,请问刚怎么做?

    4 条回复    2019-04-18 02:03:57 +08:00
    AlisaDestiny
        1
    AlisaDestiny  
       2019-04-17 23:25:47 +08:00   ❤️ 1
    在你的脚本最后一行添加:
    desc=`cat run.log`
    curl "https://sc.ftqq.com/你的 scu_key.send" -d "text=notification&desc=${desc}"
    powersee
        2
    powersee  
    OP
       2019-04-18 00:46:38 +08:00
    @AlisaDestiny 谢谢,不过这样我得每次都先把 log 清空,再写入。或许弄两个 log 就能解决吧
    powersee
        3
    powersee  
    OP
       2019-04-18 00:47:58 +08:00
    上面的脚本倒数第二个单词错了,应该是 desp,即
    text=notification&desp=${desc}"
    yuikns
        4
    yuikns  
       2019-04-18 02:03:57 +08:00   ❤️ 1
    这时候你需要 tee ?

    function my_logger() {
    local desc=$(echo $1 | tee -a run.log)
    echo "curl your desc: $1"
    }

    my_logger "my desc"
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3499 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 11:08 · PVG 19:08 · LAX 04:08 · JFK 07:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.