Thanks a lot -----Original Message----- From: Steve Bertrand [mailto:st...@ibctech.ca] Sent: Thursday, June 18, 2009 3:01 PM To: Ajay Kumar Cc: beginners@perl.org Subject: Re: "list the user working on a single file"
Ajay Kumar wrote: > Hi all > I have one requirement that > Suppose I have one file sample.txt > > I just want one mail if anybody touch this file > Can you guys suggest me how I can implement this ? Here's a very quick and dirty implementation of a program that will loop in a check/sleep cycle. If the modification time changes, the program will send out an email, and then exit immediately. YMMV. You may have to: % perldoc -f stat goto% http://m0j0.wordpress.com/2007/09/17/unix-mtime-vs-ctime/ etc to find out how to modify it to work with 'touch'ing, but nonetheless... BTW, if you use the below example verbatim, first, I feel sorry for you, second, change the email parameters or I will ensure your ISP is promptly blacklisted. ---- code ----- #!/usr/bin/perl use warnings; use strict; use Net::SMTP; my $file_to_watch = "myfile.txt"; my $mtime = (stat $file_to_watch)[9]; my $change; while (1) { $change = (((stat $file_to_watch)[9]) - $mtime); if ($change) { my $email = Net::SMTP->new('smtp.ibctech.ca'); $email->mail("tripwi...@ipv6canada.com\n"); $email->to ("ste...@ipv6canada.com\n"); $email->data(); $email->datasend("To: ste...@ipv6canada.com\n"); $email->datasend("From: ste...@ipv6canada.com\n"); $email->datasend("Subject: $file_to_watch changed\n"); $email->datasend("\n\nFilename $file_to_watch changed $change"); $email->datasend(" secs ago since last change\n\n"); $email->datasend(); $email->quit; exit(); } else { sleep(5); } } ---- end code ---- Steve -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/