# Perl trim function to remove whitespace from the start and end of the string
sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}
sub ltrim($)
{
my $string = shift;
$string =~ s/^\s+//;
return $string;
}
sub rtrim($)
{
my $string = shift;
$string =~ s/\s+$//;
return $string;
}
среда, 17 августа 2011 г.
parse liveinternet.ru
#!/usr/bin/perl use IO::File; $inputfn=(($ARGV[0] ne '')?$ARGV[0]:"hosts.txt"); print "Parsing file: $inputfn\n"; #GET "http://www.liveinternet.ru/stat/site.ru/index.html?period=month;total=yes" | grep -A 1 id_8 | tail -1 | perl -e '<>=~/\>(\d+)\</;print $1;print "\n";' #counter end $ce=(($ARGV[1] ne '')?$ARGV[1]:"0"); my $c = 0; open(F, $inputfn) or die $!; while ($a=<F>) { $a = trim ($a); if ($a ne "") { $req='GET "http://www.liveinternet.ru/stat/'; $req.=$a; $req.='/index.html?period=month;total=yes" | grep -A 2 id_8 | tail -1'; #print ($req); $str=`$req`; $str=~m/\>([\d.,]+)\0 && $c >= $ce); } close F; # Perl trim function to remove whitespace from the start and end of the string sub trim($) { my $string = shift; $string =~ s/^\s+//; $string =~ s/\s+$//; return $string; }
split access_log by months
#!/usr/bin/perl
my $in = @ARGV[0];
open (IN, $in);
my $f = '';
while (my $str =)
{
$str =~ m#\[(\d{2})/(\w{3})/(\d{4}):.*]#;
#print "$3$2 $str \n";
my $cur = "$3$2";
if ( $cur ne $f)
{
if ($f ne '') {close OUT;}
$f = $cur;
open (OUT, "> $f-$in");
print "$f-$in\n";
}
print OUT $str;
}
close IN;
close OUT;
#return 0;
exit 0;
#in: parse.pl access_log
#out: 2011Feb-access_log, ...
my $in = @ARGV[0];
open (IN, $in);
my $f = '';
while (my $str =
{
$str =~ m#\[(\d{2})/(\w{3})/(\d{4}):.*]#;
#print "$3$2 $str \n";
my $cur = "$3$2";
if ( $cur ne $f)
{
if ($f ne '') {close OUT;}
$f = $cur;
open (OUT, "> $f-$in");
print "$f-$in\n";
}
print OUT $str;
}
close IN;
close OUT;
#return 0;
exit 0;
#in: parse.pl access_log
#out: 2011Feb-access_log, ...
sendsms
#!/usr/bin/perl
#use diagnostics;
#use strict;
#use Getopt::Std;
use vars qw/ %opt /;
use Getopt::Std;
use URI::Escape;
%group = {
admins => (
"7921xxxxxxx",
"123"
),
all => (
"987",
"654"
)
};
$login='login';
$pass='pass';
$gate='1cgw.streamsms.ru';
$from='web';
sub Send
{
# print @_;
my @list=@_;
foreach $list (@list)
{
$cmd="GET \"http://$gate/sendsms.php?user=$login&pwd=$pass&sadr=$from&dadr=$list&text=$msg\"";
# $out=$cmd;
# $out=`$cmd`;
if ($opt_v==1 || $opt_d==1) { print $cmd."\n";}
if ($opt_d==1) { next; }
$out=`$cmd`;
if ($opt_v==1) { print $out."\n";}
}
}
sub usage
{
print STDERR << "EOF"; usage: $0 [-h] [-v|-d] [-g group|-n number] text of sms -h :help -v : verbose -f : from -g : group (from code), mb admins -n : phone number, 11 digits (7921xxxxxxx), without + -d : dumb mode - only show EOF exit; } if ($#ARGV<1) { #exit ("see usage"); usage(); exit(); } @admin = ('7921xxxxxxx'); @admins = ('7921xxxxxxx','7921yyyyyyy'); @test = ('123','456'); getopts ('dhvf:g:n:') ;# or usage(); usage() if $opt_h; #$msg = join (" ", @ARGV); #print %opt; $msg = uri_escape(join (" ", @ARGV)); if (length($opt_f)>0)
{
$from=$opt_f;
}
if (length($opt_g)>0)
{
#Send($group{$opt_g}); #@admins);
Send(@admins);
}
if (length($opt_n)>0)
{
Send($opt_n);
}
#use diagnostics;
#use strict;
#use Getopt::Std;
use vars qw/ %opt /;
use Getopt::Std;
use URI::Escape;
%group = {
admins => (
"7921xxxxxxx",
"123"
),
all => (
"987",
"654"
)
};
$login='login';
$pass='pass';
$gate='1cgw.streamsms.ru';
$from='web';
sub Send
{
# print @_;
my @list=@_;
foreach $list (@list)
{
$cmd="GET \"http://$gate/sendsms.php?user=$login&pwd=$pass&sadr=$from&dadr=$list&text=$msg\"";
# $out=$cmd;
# $out=`$cmd`;
if ($opt_v==1 || $opt_d==1) { print $cmd."\n";}
if ($opt_d==1) { next; }
$out=`$cmd`;
if ($opt_v==1) { print $out."\n";}
}
}
sub usage
{
print STDERR << "EOF"; usage: $0 [-h] [-v|-d] [-g group|-n number] text of sms -h :help -v : verbose -f : from -g : group (from code), mb admins -n : phone number, 11 digits (7921xxxxxxx), without + -d : dumb mode - only show EOF exit; } if ($#ARGV<1) { #exit ("see usage"); usage(); exit(); } @admin = ('7921xxxxxxx'); @admins = ('7921xxxxxxx','7921yyyyyyy'); @test = ('123','456'); getopts ('dhvf:g:n:') ;# or usage(); usage() if $opt_h; #$msg = join (" ", @ARGV); #print %opt; $msg = uri_escape(join (" ", @ARGV)); if (length($opt_f)>0)
{
$from=$opt_f;
}
if (length($opt_g)>0)
{
#Send($group{$opt_g}); #@admins);
Send(@admins);
}
if (length($opt_n)>0)
{
Send($opt_n);
}
Подписаться на:
Сообщения (Atom)