Could someone provide any idea, how could i pipe data from nc to sed (or awk, or anything) and evaluate and write to file a timestamp after each row? What i have:
# cat /etc/systemd/system/ncserver.service
[Unit]
Description=netcat listener
After=network.target
[Service]
Restart=always
RestartSec=1
ExecStart=/usr/bin/bash -c '/usr/bin/nc -n -v -l -k -p 1313 >> /opt/data/$(hostname)-$(date -u +%%y%%m%%d-%%H).txt'
[Install]
WantedBy=multi-user.target
simple listener - receives text via raw tcp, sends into the file (restarts by cron once a day to generate new file)
I want to append current timestamp to each row of text coming (at the beginning or the end of the row, doesnt matter).
Tried sed, awk, but the problem is that i cannot evaluate date
for each row - it evaluates only once, when service started.
Looks like this
109582 ? Ss 0:00 /usr/bin/bash -c /usr/bin/nc -n -v -l -k -p 1313 | /usr/bin/sed 's/^/'$(date +%s)
109583 ? S 0:00 /usr/bin/nc -n -v -l -k -p 1313
109584 ? S 0:00 /usr/bin/sed s/^/1617555467\;/g
Pipe may be not the answer at all, but i'm kinda limited by bash. Any ideas?..