Re: how to check new file generated
lina wrote: Hi, Hello, At some directory, I wish to check are there some new file generated with step* if no new generated, I wish it sleep for a while if there are some new files generated, I wish it to send am email to myself. Here is what I have came up so far, #!/usr/bin/env perl use strict; use warnings; use 5.012; use File::Glob ':glob'; use Time::HiRes qw(sleep); use Mail::Sendmail; my $old_num = 1; my $new_num; while($old_num< 100){ checkfile(); if ($new_num == $old_num){ sleep(0.1); } if ($new_num != $old_num){ $old_num = $new_num; sendmail(); } } sub checkfile{ my @filelist = bsd_glob("step*"); my $new_num = scalar(@filelist); } You don't change the value of $new_num inside the while loop so you should probably do this instead: my $old_num = 1; while ( $old_num < 100 ) { my $new_num = checkfile(); if ( $new_num == $old_num ) { sleep( 0.1 ); } else { $old_num = $new_num; sendmail(); } } sub checkfile { my @filelist = bsd_glob("step*"); return scalar @filelist; } John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: how to check new file generated
Thanks now better. Just the send email still not work. With Mail::Sendmail installed. sendmail( From=> 'lina.lastn...@gmail.com', To => 'lina.lastn...@gmail.com', Subject => 'Step coming close', Message => "Dangerous", ); Do I need set up something extra? > > > > John > -- > Any intelligent fool can make things bigger and > more complex... It takes a touch of genius - > and a lot of courage to move in the opposite > direction. -- Albert Einstein > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: how to check new file generated
I wish there is an alternative way in linux without installing use Mail::Sendmail; on bash I used mail lina.lastn...@gmail.com < report.txt Thanks, On Mon, Apr 2, 2012 at 4:07 PM, lina wrote: > Thanks now better. Just the send email still not work. With > Mail::Sendmail installed. > > sendmail( > From => 'lina.lastn...@gmail.com', > To => 'lina.lastn...@gmail.com', > Subject => 'Step coming close', > Message => "Dangerous", > ); > > Do I need set up something extra? >> >> >> >> John >> -- >> Any intelligent fool can make things bigger and >> more complex... It takes a touch of genius - >> and a lot of courage to move in the opposite >> direction. -- Albert Einstein >> >> -- >> To unsubscribe, e-mail: beginners-unsubscr...@perl.org >> For additional commands, e-mail: beginners-h...@perl.org >> http://learn.perl.org/ >> >> -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: how to check new file generated
At 4:08 PM +0800 4/2/12, lina wrote: I wish there is an alternative way in linux without installing use Mail::Sendmail; on bash I used mail lina.lastn...@gmail.com < report.txt If that works for you on your system, then just execute the same thing using system: system('mail lina.lastn...@gmail.com < report.txt'); Check 'perldoc -f system' for error checking methods. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: how to check new file generated
On Mon, Apr 2, 2012 at 11:35 PM, Jim Gibson wrote: > At 4:08 PM +0800 4/2/12, lina wrote: >> >> I wish there is an alternative way in linux without installing use >> Mail::Sendmail; >> >> on bash I used >> >> mail lina.lastn...@gmail.com < report.txt > > > If that works for you on your system, then just execute the same thing using > system: > > > system('mail lina.lastn...@gmail.com < report.txt'); Thanks. It's the one I was looking for. Thanks all for suggestions, Best regards, > > > Check 'perldoc -f system' for error checking methods. > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/