user974887
user974887

Reputation: 2499

How do I pass the tail of a log file to a command?

I have quite a few long-running processes and I use this command to text me at various points throughout a script and to let me know when something has completed:

curl http://textbelt.com/text -d number=<PHONE NUMBER> -d "message=Doneskiiz"

Instead of this basic message I would like to include the tail of a log file in the message so that I can see the last few lines to know if it was successful and to peek at the result. If possible I'd like current time included (or in a second message).

Upvotes: 1

Views: 700

Answers (2)

Horacio
Horacio

Reputation: 2965

I don't know if it something that you can do with tail and pipes, but it something that you can do with inotify library.

take a look to iwatch, that can fires an event when your file is modified and run your script.

Read this.

http://arkanis.de/weblog/2014-02-16-iwatch-run-a-command-when-a-file-changes

Upvotes: 0

pasaba por aqui
pasaba por aqui

Reputation: 3549

Steps:

a) execute "date" to retrieve current date

b) execute "tail -n nnn" to retrieve "nnn" last lines of log file

c) execute "curl" with "--data-binary @file" or "--data-binary @-" or "-F field=@filename" to post previous information.

you can see a similar example at curl: pass a named parameter from stdin:

tail -n 20 my.log | curl -d date="$(date)" -d number="555123" -F log=@- "http://somewhere" 

Upvotes: 1

Related Questions