Hi, Im designing a server-daemon which will allow me to telnet to my server and run admin tasks with a special syntax, where certain commands are run against certain programs. This is the perl-code so far:
######################################################### # Emcb Remote Access Administration Server (RAAS(iserver-0.1)) ######################################################### # All you need to do to get the server up and running... # use IO::Socket; use Net::hostent; # for OO version of gethostbyaddr # TCP Port $PORT = 9000; # pick something not in use # Create Socket Instance $client2 = IO::Socket::INET->new( Proto => 'tcp', LocalPort => $PORT, Listen => SOMAXCONN, Reuse => 1); # Cant Start Daemon die "can't setup server" unless $client2; # Daemon Up And Running print "[Server $0 accepting clients]\015\012"; while ($client2 = $client2->accept()) { # Flush The Client's STDOUT $client2->autoflush(1); # Welcome The User To The System print $client2 "Welcome to $0\015\012Type help for command list.\015 +\012"; $hostinfo = gethostbyaddr($client2->peeraddr); printf "[Connect from %s]\015\012", $hostinfo->name || $client2->pee +rhost; print $client2 "root\@iserver \$ "; while ( <$client2>) { next unless /\S/; # blank line if (/quit|exit|kill/i) { last; + } elsif (/env/i) { print $client2 `set`; } elsif (/motd/i ) { print $client2 `cat /etc/motd 2>&1`; + } elsif (/date|time/i) { printf $client2 "%s\015\012", scalar loc +altime; } elsif (/who/i ) { print $client2 `who 2>&1`; + } elsif (/cookie/i ) { print $client2 `/usr/games/fortune 2>&1 +`; } elsif (/motd/i ) { print $client2 `cat /etc/motd 2>&1`; + } else { $usage = "\015\012\015\012Usage: [exit|quit|kill] - Quit The Client [date|time] - Display The Current Date/Time [env|set] - Display The Curfrent Enviroment Variables\015\012\015\012" +; print($usage); } } continue { print $client2 "root\@iserver \$ "; } close $client2; }
But i have a few problems. When i run a command that outputs a lot of data the line breaks make it look like this: abnfjfjfjxjsjede jhcvdavchdahvdhavhadhv chdchehchaehcahec Instead of going to the beginning of a new line. And the output isnt outputed to the client, instead it comes up in my logs ( i run the cmd like: server > "/log.file" &). Can anyone help? Cheers, Elfyn

In reply to A Perl Server Daemon by emcb

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.