LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 03-02-2011, 10:38 AM   #1
dnaqvi
Member
 
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.

Thanks
D
Attached Files
File Type: txt SpaceMonitor.txt (2.1 KB, 26 views)
 
Old 03-02-2011, 11:16 AM   #2
z1p
Member
 
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:

Code:
...

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.
 
  


Reply

Tags
perl



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 12:54 PM
LSI Logic / Symbios Logic 53c875 (rev 14) -> HP Storageworks 1/8 G2 gileravxr Linux - Hardware 0 07-21-2009 04:45 AM
add an existing user to an existing group? tramni1980 Slackware 5 05-08-2008 07:28 PM
how to add existing files to existing imported kdevelop project?? santana Programming 1 05-22-2007 09:53 AM
Editing buttons (quote, code etc.) add the code to the end vharishankar LQ Suggestions & Feedback 2 09-13-2004 09:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:57 PM.

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