Sponsored Content
Top Forums Shell Programming and Scripting If I ran perl script again,old logs should move with today date and new logs should generate. Post 303014545 by Sanjeev G on Wednesday 14th of March 2018 07:10:16 AM
Old 03-14-2018
If I ran perl script again,old logs should move with today date and new logs should generate.

Appreciate help for the below issue.
Im using below code.....I dont want to attach the logs when I ran the perl twice...I just want to take backup with today date and generate new logs...What I need to do for the below scirpt..............

1)if logs exist it should move the logs with extention of today date nad need to generate new one
2) only for first log file coming perfectly and for remaining logfiles and input.txt not adding in the outputfile.

Script :

Code:
my $last_name = '';
my $writeout;
 
while(<>) {
    if (/^#(\w+)#(.+)$/) {
        if ($last_name ne $1) {
            close $writeout if $writeout;
            open($writeout, '>>', "$1.log");
        }
        $last_name = $1;
if ($. == 1) {
print $writeout "Extract $1 \n";  
my $filename="input.txt";
open (my $ip, "<" , $filename) || die ("Can't open file input.txt");
while ( <$ip> ) {
    next if  (/^$/);
    print $writeout  "$_";
}
close $ip;
}
        print $writeout "$2\n" if $writeout;
    }
}
close $writeout or die;

Input files

Code:
more sanj.txt

#ext1#test1.tale2 drop
#ext1#test11.tale21 drop
#ext1#test123.tale21 drop
#ext2#test1.tale21 drop
#ext2#test12.tale21 drop
#ext3#test11.tale21 drop
#ext3#test123.tale21 drop
#ext4#test1.tale21 drop
#ext4#test124.tale21 drop
#ext1#test1.tale2 drop

more input.txt

1.1.1.1
2.2.2.2


logfile outputs
Code:
ls ext[0-9]*.log | while read f; do printf "file: $f\n--------------\n";cat $f; echo; done


file: ext1.log

  Extract ext1 
1.1.1.1
2.2.2.2
test1.tale2 drop
test11.tale21 drop
test123.tale21 drop
test1.tale2 drop

file: ext2.log
--------------
  test1.tale21 drop
test12.tale21 drop

file: ext3.log
--------------
 test11.tale21 drop
test123.tale21 drop

file: ext4.log
--------------
  test1.tale21 drop
test124.tale21 drop

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove out date logs

hi all, i would like to write the shell script to remove the out-dated log my log file name will be like this: access_20050101.log access_20050102.log . . . access_20071007.log access_20071008.log access_20071009.log i has try to write the command as following, it will be remove the... (2 Replies)
Discussion started by: eric_wong_ch
2 Replies

2. Shell Programming and Scripting

Perl script to rotate logs

I have a shell script that will gzip/tar/archive application logs that are over 20 days old which works just fine, but I would like to convert to a Perl script. Problem is, I'm a beginner with Perl and all attempts so far have failed. Basicaly I have a log dir /app/logs that contains several... (18 Replies)
Discussion started by: theninja
18 Replies

3. Solaris

Remove logs by date

Hi I Need To Remove Logs Older Than April 1 St(4/1/2007) By Date I Have A Script To Remove 3 Months Old Like Using 90 Days Thanks (3 Replies)
Discussion started by: cvdev
3 Replies

4. Shell Programming and Scripting

script to move logs

Does anyone have a good script to move log files from a cron? There are a lot of logs, about 100 or more and they are constantly being written too. (7 Replies)
Discussion started by: photon
7 Replies

5. Shell Programming and Scripting

Grep yesterday logs from weblogic logs

Hi, I am trying to write a script which would go search and get the info from the logs based on yesterday timestamp and write yesterday logs in new file. The log file format is as follows: """"""""""""""""""""""""""... (3 Replies)
Discussion started by: harish.parker
3 Replies

6. Shell Programming and Scripting

shell script to auto process ten random files and generate logs

Hello member's I'm learning to script in the ksh environment on a Solaris Box. I have 10 files in a directory that I need to pass, as input to a batch job one by one. lets say, the files are named as follows: abcd.txt ; efgh.bat ; wxyz.temp etc. (random filenames with varied extensions ).... (1 Reply)
Discussion started by: novice82
1 Replies

7. Shell Programming and Scripting

Lots of logs to move....don't remove if open

I have a ksh script that currently moves a day's worth of log files (about 15,000) files to a different directory. The issue is that about 100 of these files are still open for write when this happens. I need an efficient way to ensure that these files aren't open without doing an lsof on each... (7 Replies)
Discussion started by: nestafaria
7 Replies

8. Shell Programming and Scripting

Script to Search Logs Several Directories Pulling out Only Current Date

Hi All.. I'm seeking assistance with editing a script to search log files in several directories. I'm close to what I'm seeking, but need additional guidance. The log files are always listed by current date; however, inside the log file includes dates that go back to 2011. What I'm... (6 Replies)
Discussion started by: lenaf7
6 Replies

9. Shell Programming and Scripting

Perl script to parse multiple windows event logs.

Hi all, I am developing a log parsing agent in perl to send windows Event logs to Zenoss Monitoring tool. Using Win32::EventLog i can able to get the Event messages but only one Eventype eg Application or System could able to parse at a time. Can you please help to how to open mutiple eventlogs... (3 Replies)
Discussion started by: kar_333
3 Replies

10. Shell Programming and Scripting

Perl script to extract last 24 hrs logs from cronlog

Hi Friends, Can anybody help me to create a perl script to generate log file for last 24 hrs from cron log file ?? Thank You (2 Replies)
Discussion started by: syamji.vm
2 Replies
Mason::Manual::Setup(3pm)				User Contributed Perl Documentation				 Mason::Manual::Setup(3pm)

NAME
Mason::Manual::Setup - Setting up Mason SETUP
Web development The most common use of Mason is to generate dynamic web content. Poet is a web framework designed specifically to work with Mason. Given an HTTP request, Poet generates a corresponding Mason request, and uses the output from Mason to form the HTTP response. Poet takes care of the web development details that are outside of Mason's domain, such as server integration and configuration. Poet::Manual::Tutorial shows how to set up a Poet/Mason site in great detail. Mason can also be used in the popular web frameworks Catalyst and Dancer, as a drop-in replacement for their default template engines. See Catalyst::View::Mason2 and Dancer::Template::Mason2. Non-web development Mason can be used to generate any kind of dynamic content. I have personally used it to generate Apache configuration files, emails, and C++ code. To use Mason from a script or library, use the Mason::Interp API: my $interp = Mason->new( comp_root => '/path/to/comps', data_dir => '/path/to/data', ... ); my $output = $interp->run( '/request/path', foo => 5 )->output(); If you want to process a directory with a mix of Mason templates and static files, check out Any::Template::ProcessDir. To try out Mason syntax from the command line, use the mason script: % mason 2 + 2 = <% 2+2 %> ^D 2 + 2 = 4 LOGGING
Mason uses Log::Any to log various events, such as the start and end of each request. You can direct thesse logs to the output of your choice; see Log::Any::Adapter. If you don't specify anything then the logs will go into the void. SEE ALSO
Mason AUTHOR
Jonathan Swartz <swartz@pobox.com> COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Jonathan Swartz. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.14.2 2012-05-02 Mason::Manual::Setup(3pm)
All times are GMT -4. The time now is 09:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy