Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
This works fine. The progam that connects to /dev/myserial receives the data and I get 2 log files that show the data that comes in and goes out of the serial port.
I am very happy with this except for 1 thing. I would like to have date and time in front of every line in the log so that I know when the data went through the serial port.
I read a lot on internet and came up with the command sequence below.
The ts command adds a date and time string before every line.
The date and time string should only go to the log files and not to the serial port otherwise the program that is using /dev/myserial does not understand the data that it receives.
Unfortunatelly I receive this:
sh: 1: Syntax error: "(" unexpected
2022/01/27 19:04:59 socat[30494] E waitpid(): child 30495 exited with status 2
I am a bit surprised that the error says sh while I am using bash. Not sure if this has something to do with the issue.
I tried at various locations in the socat command sequence to use single or double quotes but it did not help.
As a test I tried this:
echo Hello | tee >(ts > /var/log/in.log)
This works as expected. In in.log I see "Jan 27 19:13:06 Hello" without the double quotes.
Why isn't my socat command sequence working and how do I get it to work as described?
The documentation isn't clear on this, but I suspect that for a SYSTEM:<shell-command> type of address, socat forks /bin/sh which on Debian-based systems is dash.
Although I never used named pipes I understand the concept but unfortunately it is not yet working.
Data is coming from fifo1. This is data without the date and time and this data also goes to the application, which is good.
The file in.log is created but nothing is added to the file.
I have a question about these lines:
ts <fifo1 >/var/log/in.log&
ts <fifo2 >/var/log/out.log&
Because of the & at the end, the commands are running in the background.
When they exit they show the PID I believe, but if I look for this PID I do not see the ts command.
Am I missing something?
Because I tried it a couple of times I may now have several running in the background or are the removed by some mechanism?
I will have a look at it at a later date and report back.
Thanks anyway for this solution. I really appreciate it.
I do not know what went wrong the first time I tried but it works now.
The socat and tee are running for more than a day without a hitch.
The logs are filling up nicely.
Besides that I learned something new. Although I heard about named pipes I never used them.
Now that I know what it is and how to use them, I will going to use them more often.
Many thanks for the example script you published. That really helped.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.