tia_kamakshi
asked on
Finding list of files older than 30 min
Hi,
I am new to perl.
I need to find the list of xml files in few folders.
Where XML files are older than 30 min
I want the list of files in one mail from each folder
And then I wanted to mail the file
Please help me writting this is perl script
Many Thanks
I am new to perl.
I need to find the list of xml files in few folders.
Where XML files are older than 30 min
I want the list of files in one mail from each folder
And then I wanted to mail the file
Please help me writting this is perl script
Many Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many Thanks. I will try and come back to you.
How can we give mulitiple directory paths.
As there are many different directory path, where I need to check this.
Please guide
Many Thanks again
How can we give mulitiple directory paths.
As there are many different directory path, where I need to check this.
Please guide
Many Thanks again
the paths are suposed to be in @DIR_PATHS
now depends how you need to pass them,
statically
@DIR_PATHS = ("path_1", "path_2", "path_3")
by script parameters
@DIR_PATHS = @ARGV
see you tomorow
now depends how you need to pass them,
statically
@DIR_PATHS = ("path_1", "path_2", "path_3")
by script parameters
@DIR_PATHS = @ARGV
see you tomorow
ASKER
Many Thanks
I will come back to you...
I will come back to you...
ASKER
Many Thanks,
Will this script needs to be added in the crontab for every 30 min.
Or this script is itself is like schedular after 30 min
I think It would be great Idea if we execute this perl file from the schedular after every 30 min using crontab
So can you please remove schedular from the perl script
I dont wish mail, if there is no files in the folder
I am sorry for the trouble
Thanks again
Will this script needs to be added in the crontab for every 30 min.
Or this script is itself is like schedular after 30 min
I think It would be great Idea if we execute this perl file from the schedular after every 30 min using crontab
So can you please remove schedular from the perl script
I dont wish mail, if there is no files in the folder
I am sorry for the trouble
Thanks again
ASKER
Many Thanks
the time part is
my ( $mtime ) = (stat $file_path)[9];
next if $mtime + 30 * 60 < time(); # old enouf
remove it and you shall not have problems
my ( $mtime ) = (stat $file_path)[9];
next if $mtime + 30 * 60 < time(); # old enouf
remove it and you shall not have problems
ASKER
Hi,
When I execute the code you have proposed.
It gives me error below
abcdmcc@tgfr-tstva2:/usr/l ocal/appli c/cmc/admi n$ perl ListAgedFiles.pl
Global symbol "$I_DONT_HAVE_SENDMAIL" requires explicit package name at ListAgedFiles.pl line 31.
Execution of ListAgedFiles.pl aborted due to compilation errors.
abcdmcc@tgfr-tstva2:/usr/l ocal/appli c/cmc/admi n$
Please guide
I am pasting my code in code part
Thanks
When I execute the code you have proposed.
It gives me error below
abcdmcc@tgfr-tstva2:/usr/l
Global symbol "$I_DONT_HAVE_SENDMAIL" requires explicit package name at ListAgedFiles.pl line 31.
Execution of ListAgedFiles.pl aborted due to compilation errors.
abcdmcc@tgfr-tstva2:/usr/l
Please guide
I am pasting my code in code part
Thanks
#!perl
use strict;
use warnings;
use MIME::Lite;
my @DIR_PATHS = qw(/home/defg/in /home/defg/out /home/abcdmcc/RegistrationRequest /home/abcdmcc/MessageRequest /home/abcdmcc/BrochureRequest /home/abcdmcc/EmailRequest);
my %old_files;
foreach my $dir_path ( @DIR_PATHS ) {
opendir my $DIR, $dir_path or die $!;
while (my $file_path = readdir(DIR)){
next if not -f $file_path; # return if it isn't a file
push(@{$old_files{$dir_path}}, $file_path);
}
closedir($DIR);
}
while ( my ($dir_path, $files) = each %old_files ) {
my $msg = MIME::Lite->new(
From => 'dinesh.bali@pb.com',
To => 'dinesh.bali@pb.com',
Subject => "old files in $dir_path",
Data => join("\n", @$files)
);
# send the email
if ($I_DONT_HAVE_SENDMAIL) {
MIME::Lite->send('smtp', 'mail.example.com', Timeout=>60);
}
$msg->send();
}
how do you wich to send the mail, by a sendmail in the local machine? remove the
if ($I_DONT_HAVE_SENDMAIL) {
MIME::Lite->send('smtp', 'mail.example.com', Timeout=>60);
}
you have some smtp server, substitute
if ($I_DONT_HAVE_SENDMAIL) {
MIME::Lite->send('smtp', 'mail.example.com', Timeout=>60);
}
by
MIME::Lite->send('smtp', 'mail.example.com', Timeout=>60);
if ($I_DONT_HAVE_SENDMAIL) {
MIME::Lite->send('smtp', 'mail.example.com', Timeout=>60);
}
you have some smtp server, substitute
if ($I_DONT_HAVE_SENDMAIL) {
MIME::Lite->send('smtp', 'mail.example.com', Timeout=>60);
}
by
MIME::Lite->send('smtp', 'mail.example.com', Timeout=>60);
ASKER
Thanks for your quick response
Now I get the error
perl ListAgedFiles.pl
Name "main::DIR" used only once: possible typo at ListAgedFiles.pl line 14.
Please guide
Thanks for your co-operation
Now I get the error
perl ListAgedFiles.pl
Name "main::DIR" used only once: possible typo at ListAgedFiles.pl line 14.
Please guide
Thanks for your co-operation
Name "main::DIR" used only once: possible typo at ListAgedFiles.pl line 14 (#1)
(W once) Typographical errors often show up as unique variable names.
If you had a good reason for having a unique name, then just mention it
again somehow to suppress the message. The our declaration is
provided for this purpose.
NOTE: This warning detects symbols that have been used only once so $c, @c,
%c, *c, &c, sub c{}, c(), and c (the filehandle or format) are considered
the same; if a program uses $c only once but also uses any of the others it
will not trigger this warning.
you readdir(DIR), but you never open it.
the scalar $DIR is different from the bareword DIR
(W once) Typographical errors often show up as unique variable names.
If you had a good reason for having a unique name, then just mention it
again somehow to suppress the message. The our declaration is
provided for this purpose.
NOTE: This warning detects symbols that have been used only once so $c, @c,
%c, *c, &c, sub c{}, c(), and c (the filehandle or format) are considered
the same; if a program uses $c only once but also uses any of the others it
will not trigger this warning.
you readdir(DIR), but you never open it.
the scalar $DIR is different from the bareword DIR
ASKER
Thanks for expalaining.
Can you please help me fixing this in my above program
Thanks again
Can you please help me fixing this in my above program
Thanks again
I'd just use DIR for everything, but if you prefer, you could also use $DIR for everything
ASKER
Thanks allot your solution works
I have graded you at
https://www.experts-exchange.com/questions/24129385/Syntax-error-in-perl-Old-list-of-files-and-mail.html?anchorAnswerId=23609666#a23609666
Many Thanks again
I have graded you at
https://www.experts-exchange.com/questions/24129385/Syntax-error-in-perl-Old-list-of-files-and-mail.html?anchorAnswerId=23609666#a23609666
Many Thanks again
Question of taste.
Always use $DIR.
DIR becomes +- a global variable, so usually is a bad idea.
Always use $DIR.
DIR becomes +- a global variable, so usually is a bad idea.
Open in new window