Perl

Soldato
Joined
17 Jan 2006
Posts
2,890
Location
Dundee
How do everyone. I'm in a bit of a pickle and have to write a simple perl program that would be useful from a networking point of view.

I plan to write something that when run will check the free space on a hard drive and email the details to network administrator, This is soemthing that can be done on system startup for example.

Only thing is I dont have a clue as to how I go about it.

Any suggestions / ideads etc would be extremely helpful.
 
Are these windows or linux boxes? Probably easier on linux as there are system commands that can give this sort of information very easily. Also, sendmail can be used to send the mail.

For windows, you could use a module like Win32::DirSize.
 
If your talking about linux - you may as well just write a shell script. If you want it to run at regular times just cron tab it. Guess you could schedule something in windows as well.

df and (send)mail are all you need in linux.

If you really want to do it in perl. There may even be a perl API call to get hard disk space - but im not a perl coder so you will have to wait for someone else. (2 mins of googling and you would have found Mail::Internet modules for email).

Otherwise if your really wanting to write something in code you could write a daemon/background service for it.
 
Last edited:
growse said:
Are these windows or linux boxes? Probably easier on linux as there are system commands that can give this sort of information very easily. Also, sendmail can be used to send the mail.

For windows, you could use a module like Win32::DirSize.

It will run on Linux machines.

TBH it is for Uni so it does not need to be pretty, as long as it does something. I am struggling as I am in 3rd year and came straight to this from college (with no programmin skills at all). Althougt the course is Networks, it is in facvt 80% programming and web development.

Cheers
 
*nix makes life very easy.

You can use malef!c's suggested modules, or have a look on search.cpan.org for something that will do the trick. Mailing it is a simple case of using Sendmail - tonnes of stuff on the web about that.

Here's a script that sends a mail:

Code:
#!/usr/bin/perl

$sendmail = "/usr/sbin/sendmail -t";

my $reply_to = "Reply-to: reply-at\@hello.com\n";
my $subject  = "Subject: Execution is complete\n";
my $content  = "Execution of this script completed today.\n\n";
my $to       = "To: email\@domain.com\n";

open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
print SENDMAIL $reply_to;
print SENDMAIL $subject;
print SENDMAIL $to;
print SENDMAIL "Content-type: text/plain\n\n";
print SENDMAIL $content;
close(SENDMAIL);
 
Cheers for that - just have to figure out how PERL can gather information on the size and total free space of a drive.

I i can get that it will be a done deal.
 
Back
Top Bottom