Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help setting up logging from a port

Status
Not open for further replies.

fsanchez13

Technical User
May 9, 2003
35
US
I posted this on Unix Scripting Forum but after finding this one I am thinking this might be a better place to ask for help.

I am using a netra running Solaris 8 and access a terminal server via the lan that is serial connected to a ROP (read only printer) This printer outputs in plain text format and is almost a constant flow of traffic when the port is telnet to. I need a script or advice on how to establish a telnet to this port (from the netra) and create/dump the data coming accross this link to a file on the Solaris box and log anything that comes accross this link to the same long running file. Then at the end of the day (23:59) create a new file and start dumping to the new file for 24 hours and so on. Any help would be greatly appreciated

 
telnet is one of those commands, similar to passwd and a few others, that require a valid terminal device to work from. As such you cannot use telnet within an ordinary script (ksh, sh, csh, bash, etc) without using something like the "expect" tool.

To do this properly i would suggest using perl to grab the info, something like the following (excuse the bad perl; writing this on the fly so may need tweaking, and there is no error checking here). Modify at will as you require.
Code:
#!/usr/bin/perl
use strict;
use warnings;
use Net::Telnet;

open(OUTPUT, ">/tmp/output.txt"); # file to dump output
my $quittime=time()+86400; # number of seconds in period to check - this is 24 hours

my $cx = new Net::Telnet(
  Host=>"hostname",  # name of host to conenct to
  Port=> 19, # port number (this is chargen here for testing)
);

while(time() < $quittime)
{
  print OUTPUT $cx->getline();
}

N.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top