For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > August 2004 > Help Creating Script









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Help Creating Script
sbridges

2004-08-24, 9:07 am

I am new to scripting and have a script that I would like to write
butneed a bit of help actually getting the script running or actually
working out how to make it happen.


I want to pull som einformation out of a txt file created from dos / I
therefore know when the unix system is going to look at this file that
it is going to have to be cleaned or detoxed so that this removes the
carrage returns & other nasties that it dos not like.


I have a script to do that BUT


I want to amend the following data ( part of my test file )


23/08/2004 15:01 100,139,008 user1.nsf
23/08/2004 14:51 100,401,152 user2.nsf
23/08/2004 15:03 101,187,584 user3.nsf
23/08/2004 15:04 101,187,584 user4.nsf
23/08/2004 15:01 101,449,728 user5.nsf


This file is a piped directory list to .txt , I want to pull out all of
the names.nsf that are over 100,000,000 k and strip the .nsf off the
end and just be left with a , between each username.


I then want to save this list of usernames,usernames as a seporate
file, So that I can have this as a message reciptients file.


I am then going to write or have another function within the script to
send out an email saying that they are over 100mb.


you maybe looking thinking why but we are having an issue with notes
database sizes and quotas not working out and so thinking of a dos /
unix solution that we know will work and email without fail


the idea is to shedule the script to run every 15 mins and have an
automated job pull the new directory listing as well.
All help greatfully recived.


unix newbie Sally .

John W. Krahn

2004-08-24, 11:05 pm

sbridges wrote:
> I am new to scripting and have a script that I would like to write
> butneed a bit of help actually getting the script running or actually
> working out how to make it happen.
>
> I want to pull som einformation out of a txt file created from dos / I
> therefore know when the unix system is going to look at this file that
> it is going to have to be cleaned or detoxed so that this removes the
> carrage returns & other nasties that it dos not like.
>
> I have a script to do that BUT
>
> I want to amend the following data ( part of my test file )
>
> 23/08/2004 15:01 100,139,008 user1.nsf
> 23/08/2004 14:51 100,401,152 user2.nsf
> 23/08/2004 15:03 101,187,584 user3.nsf
> 23/08/2004 15:04 101,187,584 user4.nsf
> 23/08/2004 15:01 101,449,728 user5.nsf
>
> This file is a piped directory list to .txt , I want to pull out all of
> the names.nsf that are over 100,000,000 k and strip the .nsf off the
> end and just be left with a , between each username.
>
> I then want to save this list of usernames,usernames as a seporate
> file, So that I can have this as a message reciptients file.
>
> I am then going to write or have another function within the script to
> send out an email saying that they are over 100mb.
>
> you maybe looking thinking why but we are having an issue with notes
> database sizes and quotas not working out and so thinking of a dos /
> unix solution that we know will work and email without fail
>
> the idea is to shedule the script to run every 15 mins and have an
> automated job pull the new directory listing as well.
> All help greatfully recived.


See your manual for crontab (or perhaps fcrontab) to have your script run
every 15 minutes.

man crontab

Perhaps something like this may help get you started (UNTESTED):

#!/usr/bin/perl
use Net::SMTP;

my $max = 100_000_000;
my $file = 'test.txt';
my $host = 'localhost';
my $me = $ENV{ USER };

open my $FH, '<', $file or die "Cannot open $file: $!";

my @users;
while ( <$FH> ) {
my ( $size, $name ) = ( split )[ -2, -1 ] or next;
$size =~ tr/,//d; # remove commas
$name =~ s/\.nsf$//; # remove extention
push @users, $name if $size >= $max;
}

# nothing to do if no users
die "No users found.\n" unless @users;

my $smtp = Net::SMTP->new( $host );

$smtp->mail( $me );
$smtp->to( 'root' );

$smtp->data();
$smtp->datasend( "To: root\n" );
$smtp->datasend( 'CC: ' . join( ', ', @users ) . "\n" );
$smtp->datasend( "\n" );
$smtp->datasend( "Your account has exceeded the $max limit.\n" );
$smtp->dataend();

$smtp->quit;

exit 0;

__END__



John
--
use Perl;
program
fulfillment
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com