Hello, I am trying to write a PERL daemon in which I want to read all inputs from all ttys and print it to STDOUT (redirected to log) (deamonize the program and read all command line inputs as SDTIN independent of TTYs).

How to read all inputs from all ttys(or from keyboard independent of ttys) and print it to STDOUT to log it into a file "logy"?

I have a code below, part of it I found on the net and part of it I tried to modify to achive my goal. Please help me understand what is wrong in the below code and how to fix it? Thanks in advance

#!/usr/bin/perl -w use strict; use diagnostics; use Carp; use integer; # Completely dissociate from the parent tty and close file descriptors +.<br> sub daemon { local(*TTY,*NULL); exit(0) if (fork); if (open(NULL,"/dev/null")) { open(STDIN,">&NULL") || close(STDIN); open(STDOUT,">&NULL") || close(STDOUT); open(STDERR,">&NULL") || close(STDERR); } else { close(STDIN); close(STDOUT); close(STDERR); } eval 'require "sys/ioctl.ph";'; return if !defined(&TIOCNOTTY); open(TTY,"+>/dev/tty") || return; ioctl(TTY,&TIOCNOTTY,0); close(TTY); } &daemon; open(TTY,"+>/dev/pts*") || return; open(STDIN, "<&TTY") || die "reopen stdin"; ##open(STDOUT, ">&TTY") || die "reopen stout"; close TTY; open (STDOUT, ">logy"); $SIG{INT} = sub { close STDOUT; exit }; $SIG{TERM} = sub { close STDOUT; exit }; while(1) { print <>; ##this line aims print to STDOUT. but how? print $_ doesn't + work either sleep(1); }

Edit: by BazB. Added code tags.


In reply to perl daemon, redirect STDIN to read from all ttys and print to STDOUT by ayhank

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.