powersee
V2EX  ›  问与答

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

  •  
  •   powersee · Apr 17, 2019 · 2192 views
    This topic created in 2763 days ago, the information mentioned may be changed or developed.

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

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

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

    my_logger "my desc"
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2507 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 11:36 · PVG 19:36 · LAX 03:36 · JFK 06:36
    ♥ Do have faith in what you're doing.