> -----Original Message-----
> From: Karyn Williams [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, March 28, 2007 17:54
> To: [email protected]
> Subject: RE: Exiting loops
>
> At 04:10 PM 3/28/07 -0700, Wagner, David --- Senior
> Programmer Analyst ---
> WGO wrote:
> > take the o off the /o This is in essence saying you only have to
> >compile this once for the processing going on. Take that off and see
> >what happens. I believe you would use /o if you have regex has no
> >variables which are changing with each iteration.
> >
> > If you have any problems or questions, please let me know.
> >
>
> Looks like that was it. I had added that because I read
> somewhere it was
> supposed to speed up the search. Is there another way to speed it up ?
>
Karyn, The real question is how often are you doing this? How
many users are involved? Would reading the data once and collecting the
info into a hash and then reporting off the hash make sense. You are
going through the file 5 times if you input 5 ids, 10 times if you have
10 ids, etc.
So step back and look at what is needed and then see if reading
the data once and using a hash or related data field will give you the
boost you need.
> > Thanks.
> >
> > Wags ;)
> >David R Wagner
> >Senior Programmer Analyst
> >FedEx Freight
> >1.408.323.4225x2224 TEL
> >1.408.323.4449 FAX
> >http://fedex.com/us
> >
> >
> >> -----Original Message-----
> >> From: Karyn Williams [mailto:[EMAIL PROTECTED]
> >> Sent: Wednesday, March 28, 2007 15:54
> >> To: [email protected]
> >> Subject: Exiting loops
> >>
> >> I have a sh script as follows. The script worked OK until the
> >> year rolled
> >> over. My (now deleted) simple sh way of figuring the month
> >> and year blew
> >> up. I decided to rewrite the script in perl because of the
> date/time
> >> functions. It takes multiple commandline args (usernames) and
> >> checks for
> >> various information on them. Since the maillogs are so large
> >> I want to exit
> >> the first loop as soon as it is determined that the user has
> >> checked their
> >> mail.
> >>
> >> #!/bin/sh
> >>
> >> ext=`date +%Y%m`
> >>
> >> month1="200702"
> >> month2="200701"
> >> month3="200612"
> >> month4=200611
> >> month5=200610
> >> month6=200609
> >> month7=200608
> >>
> >> for i in $* ; do
> >>
> >> echo $i
> >>
> >> if test -r /export/home/$i/.forward ; then echo $i
> >> has forward file
> >> ; continue ;
> >> elif [ "`fgrep -c "user=$i" /var/adm/maillog`" -gt
> >> "0" ] ; then
> >> echo $i checked mail month 0 ; continue ;
> >> elif [ "`fgrep -c "user=$i"
> >/export/home/archives/maillog.$month1`"
> >> -gt "0" ] ; then echo $i checked mail month 1 ; continue;
> >> elif [ "`fgrep -c "user=$i"
> >/export/home/archives/maillog.$month2`"
> >> -gt "0" ] ; then echo $i checked mail month 2 ; continue;
> >> elif [ "`fgrep -c "user=$i"
> >/export/home/archives/maillog.$month3`"
> >> -gt "0" ] ; then echo $i checked mail month 3 ; continue;
> >> elif [ "`fgrep -c "user=$i"
> >/export/home/archives/maillog.$month4`"
> >> -gt "0" ] ; then echo $i checked mail month 4 ; continue;
> >> elif [ "`fgrep -c "user=$i"
> >/export/home/archives/maillog.$month5`"
> >> -gt "0" ] ; then echo $i checked mail month 5 ; continue;
> >> elif [ "`fgrep -c "user=$i"
> >/export/home/archives/maillog.$month6`"
> >> -gt "0" ] ; then echo $i checked mail month 6 ; continue;
> >> else echo $i has not checked mail in the last 6 months ;
> >> fi
> >>
> >> echo checking last for 2007 ; last -3 $i
> >> echo checking 2007 dial-up ; fgrep -c P${i}
> >> /var/adm/radacct/pleiades/detail
> >> echo checking for last modified file ; ls -lrt
> >> /export/home/$i |
> >> tail -2
> >> echo checking for newest file in public_html ; ls -lrt
> >> /export/home/$i/public_html | tail -2
> >> ls -lsu /export/mail/$i
> >> quota -v $i
> >> finger -m $i
> >>
> >> done
> >>
> >> This is what I have so far in perl:
> >>
> >> # cat tt.pl
> >> #!/usr/bin/perl -w
> >>
> >> use POSIX;
> >>
> >> # Get the current month and year
> >> my ($mon,$year) = (localtime)[4,5];
> >>
> >> # Seed nmonth
> >>
> >> my @nmonth = (1,1,1,1,$mon,$year,0,0);
> >>
> >> my $sec = 1;
> >> my $min = 1;
> >> my $hour = 1;
> >> my $day = 1;
> >> my $wday = 0;
> >> my $yday = 0;
> >>
> >> # Put the loop here
> >> my $a = 1;
> >> while ($a < 7) {
> >>
> >> my $current = mktime($sec, $min, $hour, $day, $nmonth[4],
> >> $nmonth[5], $wday, $yday); # Make new timestamp for the first
> >> @nmonth = localtime($current); # Make an
> >> array out of the
> >> timestamp to get the month and year
> >> my $ext_mon = ($nmonth[4] + 1); # Pull the
> >> month out of the
> >> array and add 1 to get month number
> >> my $ext_year = ($nmonth[5] + 1900); # Pull the
> >> year and add
> >> 1900 to get the actual year
> >> if ($ext_mon <= 9) { # Make the
> >> month have two
> >> places and write the var $ext
> >> $ext = $ext_year . '0' . $ext_mon;
> >> }
> >> else {
> >> $ext = $ext_year . $ext_mon;
> >> }
> >>
> >> push (@flist, $ext);
> >> $current = $current - 86400; # Subtract one day
> >> from the first
> >> timestamp to get the month before
> >> @nmonth = localtime($current); # Make an
> >> array out of the
> >> new timestamp for the next round
> >> }
> >> continue {
> >> $a++;
> >> }
> >>
> >> # This is the part I am having trouble with :
> >>
> >> foreach $k (@ARGV) {
> >>
> >> if (-e ("/export/home/$k/.forward")) {
> >> print "User $k has a forward file.\n\n" ; next ;
> >> } else {
> >>
> >> open MAILLOG, "/var/adm/maillog" or die "couldn't
> >> open maillog :
> >> $!\n";
> >> if ($count = grep /user=$k/o, <MAILLOG> ) {
> >> print "$k checked mail $count times in
> >> /var/adm/maillog.\n"; next ;
> >> } else {
> >> close MAILLOG;
> >>
> >> open MAILLOG,
> "/export/home/archives/maillog.$flist[1]" or die
> >> "couldn't open maillog.$flist[1] : $!\n";
> >> if ($count = grep /user=$k/o, <MAILLOG> ) {
> >> print "$k checked mail $count times in
> >> maillog.$flist[1].\n"; next ;
> >> } else {
> >> close MAILLOG;
> >>
> >> open MAILLOG,
> "/export/home/archives/maillog.$flist[2]" or die
> >> "couldn't open maillog.$flist[2] : $!\n";
> >> if ( $count = grep /user=$k/o, <MAILLOG> ) {
> >> print "$k checked mail $count times in
> >> maillog.$flist[2].\n"; next ;
> >> } else {
> >> close MAILLOG;
> >>
> >> open MAILLOG,
> "/export/home/archives/maillog.$flist[3]" or die
> >> "couldn't open maillog.$flist[3] : $!\n";
> >> if ( $count = grep /user=$k/o, <MAILLOG> ) {
> >> print "$k checked mail $count times in
> >> maillog.$flist[3].\n"; next ;
> >> } else {
> >> close MAILLOG;
> >>
> >> open MAILLOG,
> "/export/home/archives/maillog.$flist[4]" or die
> >> "couldn't open maillog.$flist[4] : $!\n";
> >> if ( $count = grep /user=$k/o, <MAILLOG> ) {
> >> print "$k checked mail $count times in
> >> maillog.$flist[4].\n"; next ;
> >> } else {
> >> close MAILLOG;
> >>
> >> open MAILLOG,
> "/export/home/archives/maillog.$flist[5]" or die
> >> "couldn't open maillog.$flist[5] : $!\n";
> >> if ( $count = grep /user=$k/o, <MAILLOG> ) {
> >> print "$k checked mail $count times in
> >> maillog.$flist[5].\n"; next ;
> >> } else {
> >> close MAILLOG; print "$k has not checked their mail
> >> in the last 6
> >> months.\n";
> >>
> >> }
> >> }
> >> }
> >> }
> >> }
> >> }
> >>
> >> }
> >> }
> >>
> >>
> >> Input and output looks like this:
> >>
> >> # ./tt.pl karyn smurphy root
> >> karyn checked mail 2864 times in /var/adm/maillog.
> >> smurphy checked mail 2864 times in /var/adm/maillog.
> >> root checked mail 2864 times in /var/adm/maillog.
> >> #
> >>
> >> Yes, it goes to the next arg but as you can see, it returns
> >> the same count
> >> for each subsequent arg.
> >>
> >> I feel that my braces are (all/part/some) of the problem,
> but not sure
> >> how/what. Any suggestions would be appreciated.
> >>
> >>
> >> --
> >>
> >> Karyn Williams
> >> Network Services Manager
> >> California Institute of the Arts
> >> [EMAIL PROTECTED]
> >> http://www.calarts.edu/network
> >>
> >> --
> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >> For additional commands, e-mail: [EMAIL PROTECTED]
> >> http://learn.perl.org/
> >>
> >>
> >>
> >
> >*************************************************************
> *********
> >This message contains information that is confidential and
> proprietary to
> FedEx Freight or its affiliates. It is intended only for the
> recipient
> named and for the express purpose(s) described therein. Any
> other use is
> prohibited.
> >*************************************************************
> *********
> >
> >
> >
> --
>
> Karyn Williams
> Network Services Manager
> California Institute of the Arts
> [EMAIL PROTECTED]
> http://www.calarts.edu/network
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/