# Stream Any Log File to Slack Using curl

When was the last time you had to execute a long-running script and wished you could monitor the progress remotely without setting up a plethora of systems? For us, it was yesterday. And doing that was so simple, we had to share it. At [Postman](https://www.postman.com/), we use [Slack](https://slack.com/) for a lot of stuff, having it report the progress of an arbitrary script was simply natural. The following piece of code [tails](https://en.wikipedia.org/wiki/Tail_(Unix)) a file and for every new line added to the file, streams it to a [slack incoming webhook](https://api.slack.com/incoming-webhooks) using [curl](https://en.wikipedia.org/wiki/Curl).

```
#!/bin/bash

tail -n0 -F "$1" | while read LINE; do
  (echo "$LINE" | grep -e "$3") && curl -X POST --silent --data-urlencode \
    "payload={\"text\": \"$(echo $LINE | sed "s/\"/'/g")\"}" "$2";
done
```

  To use this script, save it as an executable script and simply pass the path to the log file and a webhook url to this script. ```
./tail-slack.sh "file.log" "https://hooks.slack.com/services/...";
```

 If you want this script to keep running even after you have logged out of your SSH terminal, use [nohup](https://en.wikipedia.org/wiki/Nohup) command. You can even make this script send the line to slack only when a particular keyword is found by sending the keyword as a third parameter. ```
./tail-slack.sh "/var/log/ngix/access.log" \
  "https://hooks.slack.com/services/..." " 404 ";
```

 The above example tails an [nginx](https://en.wikipedia.org/wiki/Nginx) [access log](https://www.nginx.com/resources/admin-guide/logging-and-monitoring/#access_log) and streams the line to slack when it has a 404 response. How simple and cool is that!