Код: Выделить всё
{
# Script from podarok66, may 2014.
:global temprx ;
:global temptx ;
:local rx [/interface get [find name=ether1] rx-byte] ;
:local tx [/interface get [find name=ether1] tx-byte] ;
:if ([:len [/file find name=rx.txt]]>0) do={
/file set [/file find name=rx.txt] content=(( $rx - $temprx ) + [/file get [find name=rx.txt] content]) ;
} else={/file print file=rx.txt;
:delay 5 ;
/file set [/file find name=rx.txt] content=$rx ;
}
:if ([:len [/file find name=tx.txt]]>0) do={/file set [/file find name=tx.txt] content=(( $tx - $temptx ) + [/file get [find name=tx.txt] content]) ;
} else={/file print file=tx.txt ;
:delay 5 ;
/file set [/file find name=tx.txt] content=$tx ;
}
:set temprx $rx ;
# :put "temprx=$temprx" ;
:set temptx $tx ;
# :put "temptx=$temptx" ;
:local rdata "01"
:local year [:pick [system clock get date] 7 11 ];
:local months [:toarray "jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec"] ;
:local month [:pick [system clock get date] 0 3 ];
:local month2 ;
:local day [:pick [system clock get date] 4 6 ]
:for mindex from=0 to=[:len $months] do={
:if ([:pick $months $mindex] = $month) do={:set month2 ($mindex-1) }
};
:if ($month2 = -1) do={:set month2 11 ; :set year ($year - 1) };
# :put [:pick $months $month2];
# :put [$year];
:if ($day=$rdata) do={:local smtpserv [:resolve "smtp.gmail.com"];
:local Eaccount "ПОЧТОВЫЙ АДРЕС";
:local pass "ПАРОЛЬПОЧТЫ";
:local reporttheme ("Traffic Report " . $year . "-" . $month . "-" . $day);
:local rxreport [/file get [/file find name=rx.txt] content];
:local simplKbrxreport ($rxreport / 1024);
:local lowKbrxreport ((($rxreport - ($simplKbrxreport * 1024)) * 1000) / 1024);
:local Kbrxreport ("$[$simplKbrxreport]".",".[:pick "$[$lowKbrxreport]" 0 2] );
# :put $Kbrxreport
:local simplMbrxreport ($rxreport / 1048576);
:local lowMbrxreport ((($rxreport - ($simplMbrxreport * 1048576)) * 1000000) / 1048576);
:local Mbrxreport ("$[$simplMbrxreport]".",".[:pick "$[$lowMbrxreport]" 0 2] );
# :put $Mbrxreport;
:local simplGbrxreport ($rxreport / 1073741824);
:local lowGbrxreport ((($rxreport - ($simplGbrxreport * 1073741824)) * 1000000000) / 1048576);
:local Gbrxreport ("$[$simplGbrxreport]".",".[:pick "$[$lowGbrxreport]" 0 2] );
# :put $Gbrxreport;
:local txreport [/file get [/file find name=tx.txt] content];
:local simplKbtxreport ($txreport / 1024);
:local lowKbtxreport ((($txreport - ($simplKbtxreport * 1024)) * 1000) / 1024);
:local Kbtxreport ("$[$simplKbtxreport]".",".[:pick "$[$lowKbtxreport]" 0 2] );
# :put $Kbtxreport;
:local simplMbtxreport ($txreport / 1048576);
:local lowMbtxreport ((($txreport - ($simplMbtxreport * 1048576)) * 1000000) / 1048576);
:local Mbtxreport ("$[$simplMbtxreport]".",".[:pick "$[$lowMbtxreport]" 0 2] );
# :put $Mbtxreport;
:local simplGbtxreport ($txreport / 1073741824);
:local lowGbtxreport ((($txreport - ($simplGbtxreport * 1073741824)) * 1000000000) / 1048576);
:local Gbtxreport ("$[$simplGbtxreport]".",".[:pick "$[$lowGbtxreport]" 0 2] );
# :put $Gbtxreport;
:local conbody ("Traffic Report for " . [:pick $months $month2] . "-" . [:pick [:if ([:pick $months $month2]!="dec") do={$year} else={($year - 1)}] 1] . "
Incoming traffic - " . $Kbrxreport . "Kb" . ";" . "
" . $Mbrxreport . "Mb" . ";" . "
" . $Gbrxreport . "Gb" . "." . "
" . "Outbound traffic - " . $Kbtxreport . "Kb" . ";" . "
" . $Mbtxreport . "Mb" . ";" . "
" . $Gbtxreport . "Gb" . ".");
:delay 2;
# :put $conbody;
/file remove [find name=report.txt];
:delay 3;
/file print file=report.txt;
:delay 5;
/file set [find name=report.txt] content=$conbody ;
:delay 5;
/tool e-mail send from="<$Eaccount>" to=$Eaccount server=$smtpserv port=587 user=$Eaccount password=$pass start-tls=yes file=report.txt subject=$reporttheme body=$conbody ;
:delay 20;
/file remove [find name=rx.txt];
/file remove [find name=tx.txt]
}
Если выкинуть все переводы трафика из одних единиц в другие, вполне себе скромный скрипт должен выйти...