Here are two perl scripts that I have. I didn't write them (a good friend of mine is a Perl Demi-god and can and has written almost everything in perl)
This was in response to someone asking for a script that would read a file and output all IP addresses:
perl -n -e "/(^|\D)([01]?\d?\d|2[0-4]\d|25[0-5])\.([01]?\d?\d|2[0-4]\d|25[0-5])\.([01]?\d?\d|2[0-4]\d|25[0-5])\.([01]?\d?\d|2[0-4]\d|25[0-5])(\D|$)/g
&& print \"$2.$3.$4.$5\n\";" /var/log/messages
This is what I use for my weblogs. I run it as a shell script:
#!/bin/sh
#
/usr/bin/perl -e 'for(reverse<>){s \n/
\n/;print;}' /var/log/authlog > /var/www/htdocs/authlog.html
/usr/bin/perl -e 'for(reverse<>){s/\n/
\n/;print;}' /var/log/daemon > /var/www/htdocs/daemon.html
/usr/bin/last > /var/www/htdocs/lastlog.html
/usr/bin/perl -i.orig -p -e 's/\n/
\n/' /var/www/htdocs/lastlog.html
/usr/bin/perl -e 'for(reverse<>){s/\n/
\n/;print;}' /var/log/maillog > /var/www/htdocs/maillog.html
/usr/bin/perl -e 'for(reverse<>){s/\n/
\n/;print;}' /var/log/messages > /var/www/htdocs/messages.html
/usr/bin/perl -e 'for(reverse<>){s/\n/
\n/;print;}' /var/log/secure > /var/www/htdocs/secure.html
/usr/bin/perl -e 'for(reverse<>){s/\n/
\n/;print;}' /var/log/ipflog > /var/www/htdocs/ipflog.html
/bin/chmod 644 /var/www/htdocs/*.html
Dusty
-----------------------------------------------
> I am trying to learn PERL, specifically for some html creation uses,
> could you email me the programs for study? As a matter of fact, ANYone
> who has ANY PERL scripts that they personally have written for some
> useful purpose, if you would e-mail it to me along with a description of
> what it does, why you wrote it and what (if anything) it replaces, I
> would greatly appreciate it. I know the web has lots of PERL scripts
> there, but I am looking for the really short, really useful scripts that
> are written day to day with no fanfair and not worth publishing.
> Basically, I am interested in 10-50 line 'extraction and report'
> programs, not mp3 encoders or irc clients. BTW, what is IDS?
>
> Regards,
> Brian
>
> ---
> You are currently subscribed to luau as: dusty@sandust.com
> To unsubscribe send a blank email to $subst('Email.Unsub')