Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl script required to check when directories, files hav been updated

Status
Not open for further replies.

tartanarmy

Technical User
Joined
Aug 31, 2007
Messages
2
Location
GB
Hi

Hope someone can point me in the right direction. I require a Perl script to allow automated checks to verify if a directory or file has been updated on a Unix server. For example to monitor the disk space used.



Cheers
 
Well.. which one do you want?

You can just do a df -k or something and get the output of it or you can set up a script to monitor certain directories and see if the file ages have changed.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
I have used the df -ks to find out and report all directories that are of interest to me. But yeah your right I require a script to automate this functionality i.e. to monitor possibly 5 dirs that would be filling up regularly.

 
Perl does not do anything automatically. You would need to write a perl script and run it as a cron job. But I am guessing this entire task could be done by the operating system. You might want to ask on Unix forum, there is probably already some application that does what you need as it sounds quite common.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
The [tt]stat()[/tt] function ( gives information about files and filehandles, including size and modifcation times.

The File::Find module is great for recursively descending into directories. It calls a specified call-back function on each path encountered.

Your script could define a global to hold the total size and a call-back function which first checks that $_ is a file (using [tt]-f[/tt]) then calls stat on it and adds the returned size to the total. You'd then call File::Find with your call-back function and a starting directory and, on return the global would contain the total of the file sizes.

If you put the whole thing in a block and declare both the total (with [tt]my[/tt]) and the sub inside the block, then the call-back sub acts as a closure and you don't need worry about anything being global.

Have a go and post back if you hit problems.

["]As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.["]
--Maur
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top