Most logs on my Mac have a time stamp before the output message like this:
Nov 14 17:55:24 - SoftRAID Driver: SoftRAID driver loaded, version 5.8.1.
I am running an executable in cron and instead of using mail I want to output all info to a log file and add a timestamp to each line in front of the output. I am using >>
to append to a single file.
This is my crontab:
SHELL=/bin/bash
MAILTO=""
* 6-23 * * * /usr/local/bin/urlwatch >> /Users/john/cronjobs/urlwatch.log
This is what I get in urlwatch.log
UNCHANGED: (01)urlwatch update released (https://github.com/thp/urlwatch/releases/latest)
How do I make the output look like this:
Nov 14 17:55:24 - UNCHANGED: (01)urlwatch update released (https://github.com/thp/urlwatch/releases/latest)
I have tried many different suggestions from across the web and have had no luck. If saving to a text file is easier that will work as well.
Tried this which is close:
* 6-23 * * * (date && /usr/local/bin/urlwatch) >> /Users/john/cronjobs/urlwatch.log
Output in the log file looks like this:
Sun Mar 15 13:35:00 CDT 2020
UNCHANGED: (03)RansomWhere? Objective-See (https://objective-see.com/products/ransomwhere.html)
UNCHANGED: (01)urlwatch update released (https://github.com/thp/urlwatch/releases/latest)
UNCHANGED: (02)urlwatch webpage (https://thp.io/2008/urlwatch/)
ts
command? – steeldriver Mar 15 '20 at 19:07urlwatch 2.17
andunchanged: true
in$HOME/.urlwatch/urlwatch.yaml
and every time I runurlwatch
it shows whole HTML code of the page and 2x UNCHANGED lines:01. UNCHANGED: https://github.com/thp/urlwatch/releases/latest
andUNCHANGED: https://github.com/thp/urlwatch/releases/latest
. Do you mean you always get a single line that saysUNCHANGED: (01)urlwatch update released (https://github.com/thp/urlwatch/releases/latest)
? – Arkadiusz Drabczyk Mar 15 '20 at 19:09/usr/local/bin/urlwatch | /path/to/ts >> /Users/john/cronjobs/urlwatch.log
(I don't know what/path/to/
is for homebrew installed executables) – steeldriver Mar 15 '20 at 19:42-i
flag but had strange output. – John Mar 15 '20 at 19:59urlwatch
is buffering its output? – steeldriver Mar 15 '20 at 20:05date
inside of a cron tab job? – steeldriver Mar 15 '20 at 20:26urlwatch
is definitely buffering its output. Time is exactly the same for each line including milliseconds. Not sure of a way around this. – John Mar 15 '20 at 20:33