Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Execute a command each time curl outputs a newline

I’m trying to use curl to infinitely stream messages from a remote server.

I periodically receive notifications like this:

$ curl -s https://my-server.com/status
Backup in progress...
Backup completed.
Disk space is about to fill up.

I want send_notify to be executed each time curl outputs a new line.
I created the script below, but it did not work.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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 

Please help me understand why this is not working and how to make it work.

I’m a beginner, I would appreciate any help! (and please forgive my poor English)

>Solution :

You need to read the output lines in a loop:

stdbuf -oL curl -s https://my-server.com/status |
    while read line ; do
        notify-send Status "$line"
    done
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading