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.
Been a while since I worked on serial but back then we simply added a tee statement to the start line in /etc/inittab. We did that a lot for serial interfaces where we wanted to see the traffic.
I guess first I'll have to epxlain that basically in Linux/Unix you have the concept of "standard" file handles. The 3 basic ones are standard input (stdin), standard output (stdout) and standard error (stderr). stdout is file handle 1 and stderr is file handle 2.
By default stdout and stderr both point to the display device you are using. They can be redirected. This is commonly done with items going to a log file. A good example is "ls -l"
Do "ls -l" and you'll see a list of files on your screen.
Do "ls -l 2>/tmp/testlog1" and you'll see the list of files on your screen. If there were any errors (unlikely in a simple ls) you'd see them in the file /tmp/testlog1. (Type "cat /tmp/testlog1" to see its contents.)
Do "ls -l >/tmp/testlog2" and you will NOT see the list of files on your screen. However if you look at /tmp/testlog2 (cat /tmp/testlog2) you'll see it contains all the files. (Note: If file handle number isn't specified as in prior example it is assumed to be file handle 1, stdout.)
Typically in logging you want BOTH the stdout and the stderr to go to the file so the syntax would be "ls -l >/tmp/testlog3 2>&1". In this case nothing will appear in your screen. The file list AND any errors will appear in your log file. The "2>&1" says to redirect stderr into stdout.
Note that it is important the ">/tmp/testlog3" appear BEFORE the "2>&1". If you had it the other way then 2 would go to your display because at the time you set its redirection that was where 1 was set. Restated you must set 1 before you set 2 if you want them both to go to the same location with the above syntax.
In addition to redirection as described above there is the concept of piping. By default the pipe sign (veritical bar, | ) takes anything from stdout and pipes it into the command following the pipe sign.
All of this leads us to the "tee" command which is used to duplicate output to the display AND to a file. So doing "ls -l |tee /tmp/testlog4" will show the list of files on your screen AND write the list to the file /tmp/testlog4. Any errors if they occur would only appear on the screen and not in the file.
Since pipe does NOT deal with stderr you have to also redirect stderr BEFORE the pipe so it goes to stdout which is then acted upon by the pipe. "ls -l 2>&1 |tee /tmp/testlog5" would therefore first redirect stderr to stdout then pipe stdout to tee. Tee would then show everything from ls -l on the screen AND write the list to /tmp/testlog5.
You'd need to modify your inittab entry so that whatever it currently sends to the device is tee'd to the file you want. Also for interfaces we used to redirect IN from the stdin. There are likely examples of such inittab entries. Unfortunately as I've mentioned before it has been a long time since I did one so I can't give you a good example.
For more detail on the tee command just type "man tee" or "info tee". FYI: Most Unix/Linux commands have a "man" (manual) page and in Linux typing "info" will show you the "man" page as well as any extended information if it exists.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.