Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Jun 7th, 2005, 3:23 AM   #1
sonson
Newbie
 
Join Date: Jun 2005
Posts: 8
Rep Power: 0 sonson is on a distinguished road
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;
sonson is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:07 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC