Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-02-2011, 11:38 AM   #1
Registered: Oct 2009
Posts: 117

Rep: Reputation: 15
Add logic in the existing code

I have a existing perl script.
This is our space monitor script.

Current Function of the Script:

If any file system exceed 90% following action do as below:

Script will create a output file which contains any new file created in the system in last 24 hours and any file over 100 MB. This file will send via email to the defined users. And file will deleted from the the System via script.

Current FS in the script:

( '/', '/dev', '/opt', '/tmp', '/var', '/usr );

In addition to above we want to do as follows:

We want to add two mounted file system as /mnt/backup_1 & /mnt/backup_2 in the logic.

We want any /mnt/ server will trigger when its over 95%, rest of the FS should be same as before 90%.

We do not want to delete output file from the System. We also do not want to send whole output file via email, we want to send only notification via email which state that specific FS is over 90% or 95% and please check /home/wasadmin/space for the FSWatch.log.

I have attached script.
Please have a look at it.

Attached Files
File Type: txt SpaceMonitor.txt (2.1 KB, 16 views)
Old 03-02-2011, 12:16 PM   #2
Registered: Jan 2011
Location: the right coast of the US
Distribution: Ubuntu 10.04
Posts: 80

Rep: Reputation: 23
It seems like the simplest way to modify the script is to take the body of the for loop and create a function that takes a filesystem name and a threshold value as parameters. Then create a second list of file systems and add a second loop for that list using the higher threshold.

Something like the following:


my $mnt_threshold = 95;
@mnt_fs ( '/mnt/backup_1', '/mnt/backup_2');

process_fs {
     my($fs, $threshold) = @_;  #subroutine parameters

    undef @new_files;
    undef @big_files;
    @lines = `df -k $fs`;
    $lines[ -1 ] =~ /(\d+)\%/;
    ...  # The rest of the for loop

foreach my $fs ( @fs ) {
  process_fs ($fs, $threshold);

foreach my $mnt_fs ( @fs ) {
  process_fs ($fs, $mnt_threshold);
To not remove the log file then remove the unlink command the script, but you need to put in place some way to clean up the log files, even if it is to say someone needs to delete the log file after it is read.

As far as sending the email. A quick google of "perl email" will provide lots of ways to do it.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Add existing unix user to existing LDAP antoniemail Linux - Server 7 06-23-2010 01:54 PM
LSI Logic / Symbios Logic 53c875 (rev 14) -> HP Storageworks 1/8 G2 gileravxr Linux - Hardware 0 07-21-2009 05:45 AM
add an existing user to an existing group? tramni1980 Slackware 5 05-08-2008 08:28 PM
how to add existing files to existing imported kdevelop project?? santana Programming 1 05-22-2007 10:53 AM
Editing buttons (quote, code etc.) add the code to the end vharishankar LQ Suggestions & Feedback 2 09-13-2004 10:32 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:22 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration