我正在嘗試使用 curl 從遠程服務器無限流式傳輸訊息。
我會定期收到這樣的通知:
$ curl -s https://my-server.com/status
Backup in progress...
Backup completed.
Disk space is about to fill up.
我想send_notify在每次curl 輸出新行時執行。
我在下面創建了腳本,但它不起作用。
notify_pipe() {
read -r msg
notify-send "$msg"
}
# Does nothing, just a blinking cursor.
stdbuf -oL curl -s https://my-server.com/status | notify_pipe
請幫助我理解為什么這不起作用以及如何使它起作用。
我是初學者,我會很感激任何幫助!(請原諒我糟糕的英語)
uj5u.com熱心網友回復:
您需要回圈讀取輸出行:
stdbuf -oL curl -s https://my-server.com/status |
while read line ; do
notify-send Status "$line"
done
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/519926.html
上一篇:awk迭代地替換陣列中的字串
