|
Writing to file
Hey everyone! This is a suburb site that i discovered..it really helped me..
i just have a problem and hope someone would be able to help me...its pretty simple question..
ok what i have here in my script is a something that login to a port and reads logs from its and writes these logs into files which are created and stored in the system. i got 3/4 of script going and it works perfect by capturing the logs continously..what i need is to add some extra things....right now what is does is that ir writes to the file opeend contiously but what i want it to do is to create a file for each day so when it reaches 11.59pm..it creates a new files with the new date and starts storing the logs to it and so on ...hence when i want to access the file for a specific date at anytime i can do so...
any one can ehlp with that...what isma guseiing is that it will b a while loops which will creates a new file whenever it notices a chaneg in date ...
how do u do tht..any idea or scripts would b great..iam sure there is a script that would b written for that purpose already...thnks in advance,...
my script is the following..
#! /usr/bin/perl -w
# client1.pl - a client
#----------------
use strict;
use Socket;
use POSIX 'strftime';
# initialize host and port
my $host = shift || '172.xx.10.30';
my $port = shift || 5221;
my $proto = getprotobyname('tcp');
# get the port address
my $iaddr = inet_aton($host);
my $paddr = sockaddr_in($port, $iaddr);
# create the socket, connect to the port
socket(SOCKET, PF_INET, SOCK_STREAM, $proto) or die "socket: $!"; connect(SOCKET, $paddr) or die "connect: $!";
my @t = localtime(time) ;
open(OUTPUT_FILE, ">>/data2/elsonba/zizo/" . ($t[5]+1900) . "-" . ($t[4]+1) . "-$t[3].log");
select OUTPUT_FILE; $| = 1;
my $line;
while (<SOCKET>)
{
print OUTPUT_FILE "$_\n";
}
close SOCKET or die "close: $!";
close OUTPUT_FILE;
|