Complete.Org: Mailing Lists: Archives: discussion: July 2001:
[aclug-L] Re: Serial port logging and redirection?
Home

[aclug-L] Re: Serial port logging and redirection?

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: discussion@xxxxxxxxx
Subject: [aclug-L] Re: Serial port logging and redirection?
From: Tom Hull <thull@xxxxxxxxxxx>
Date: Mon, 23 Jul 2001 15:45:17 -0500
Reply-to: discussion@xxxxxxxxx

Cheez-Czar wrote:
> 
> not being the most knowledgeable about devices, but with the idea that
> everything is a file, here is my idea
> 
> cat /dev/ttyS0 tee log > /dev/ttyS1

Of course, Clint meant:

  cat /dev/ttyS0 | tee log > /dev/ttyS1

The main problem with this is that tee(1) usually buffers its output (especially
to log), which means that data can get stuck inside tee's own buffers.

The script(1) program may work better in some cases (e.g., logging a telnet
session).

> On Mon, 23 Jul 2001, james l wrote:
> 
> >
> > is there some way to redirect input from say ttyS0 to both, a log file and
> > ttyS1 under linux? Aside from writing my own program, is there an easy way 
> > to
> > do this?

It's pretty close to trivial to write such a program -- just use 
read(2)/write(2).
Where:

    #define BUFMAX 4096  /* size of buffer to use, multiple of block size,
                            and <= maximum pipe buffer */
    char buf[BUFMAX];    /* buffer to use */
    int in_fd;           /* input file descriptor */
    int out_fds[];       /* output file descriptors */
    int i, nfd;          /* number of output file descriptors */
    size_t sz;           /* read(2) size */

The basic loop is:

    while ((sz = read(in_fd, buf, BUFMAX)) != (size_t) -1) {
        for (i = 0; i < nfd; i++) {
            write(out_fds[i], buf, sz);
        }
    }

Most likely, someone else has indeed written this program. Question is, how long
does it take to find it?

> > James L

-- 
/*
 *  Tom Hull * thull at kscable.com * http://www.ocston.org/~thull/
 */
-- This is the discussion@xxxxxxxxx list.  To unsubscribe,
visit http://tmp2.complete.org/cgi-bin/listargate-aclug.cgi


[Prev in Thread] Current Thread [Next in Thread]