:if ([/interface get [find name="interface"] running]=!true) do={:log warning "Possible Power Outage"}
第二个 备份userman数据库,以日期为名称,加入计划任务即可使用,5.11测试通过
/tool user data save name ([:pick [/system clock get date] 7 11] . [:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6])
第三个 清理客户端下线后的地址列表,可以添加白名单
{
:local ip
/ip firewall address-list
:foreach i in=[find list=ok_List comment!=admin] do={
:set ip [get $i address]
:if ([:len [/ip address find dynamic=yes network=$ip]]=0) do={remove $i}}}
来个重量级的实用脚本,自动备份各种备份到邮箱
#SMTP伺服器位置
:local SMTP "smtp.163.com"
#寄件人
:local MailFrom ""
#收件人
:local MailTo ""
#寄出後是否刪除已存檔的Log(/file裡的檔案)
#0=保留 1=刪除
:local DeleteLogFile 1
:local BackupFileName
:set BackupFileName ([/system identity get name] . "_Backup-" . [:pick [/system clock get date] 7 11] . [:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6] . ".umb");
/tool user-manager database save name=($BackupFileName);
delay 10;
/tool e-mail set from=$MailFrom;
/tool e-mail set address=[:resolve $SMTP];
/tool e-mail send to=$MailTo subject=([/system identity get name] . " -- 中牟汇银 " . [:pick [/system clock get date] 7 11] . [:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6]) file=[$BackupFileName];
:delay 10;
:if ($DeleteLogFile =1) do={
/file rem [/file find name=($BackupFileName)];
}
:log info ("System Backup emailed at " . [/sys cl get time] . " " . [/sys cl get date] . " (CHT:備份email寄出)");
********************************************************************************************
三个邮件备份,只有这个我测试成功了 很郁闷的感觉,不能发送邮件问别人都不搭理的
********************************************************************************************
这个是删除PPP 中活动链接中重复的链接的, 找了好长时间。。
:local userX;
:local userY;
:local i;
:local u;
:local clogged 0;
:local addr;
:local addr2;
:foreach i in=[/ppp active find] do={
:set userX [/ppp active get $i name];
:set clogged 0;
:foreach u in=[/ppp active find name=$userX ] do={
:set clogged (clogged +1);
:if (clogged>1) do={
:set userY [/ppp active get $u name];
:set addr [/ppp active get $u caller-id];
:set addr2 [/ppp active get $i caller-id];
:if ($addr != addr2) do={
:log info "MPPP: FIRST ACTIVE <<$userX>> FROM IP $addr2";
:log info "MPPP: THE $clogged° <<$userY>> CALLING FROM IP $addr NOW DISCONNECTED";
/ppp active remove $u;
}
}
}
}
------------------------------------------------------------------------
保证PPPOE只有一个活动会话,多出来的都删除
:local userX;
:local userY;
:local i;
:local u;
:local clogged 0;
:local addr;
:local addr2;
:foreach i in=[/ppp active find] do={
:set userX [/ppp active get $i name];
:set clogged 0;
:foreach u in=[/ppp active find name=$userX ] do={
:set clogged (clogged +1);
:if (clogged>1) do={
:set userY [/ppp active get $u name];
:set addr [/ppp active get $u caller-id];
:set addr2 [/ppp active get $i caller-id];
:if ($addr != addr2) do={
:log info "MPPP: FIRST ACTIVE <<$userX>> FROM IP $addr2";
:log info "MPPP: THE $clogged° <<$userY>> CALLING FROM IP $addr NOW DISCONNECTED";
/ppp active remove $u;
}
}
}
}
**********************************
ros自带PPPOE自动绑定MAC地址,非radius环境
/ppp secret;
:foreach pppuser in [find caller-id=""] do={
:local user [get $pppuser name];
/ppp active
:foreach pact in [find name=$user] do={
:local mac [get $pact caller-id];
/ppp secret set [/ppp secret find name=$user] caller-id=$mac;
}}
*********************************************
/ip firewall mangle
add action=mark-connection chain=prerouting comment=test disabled=no dscp=6 in-interface=pppoe new-connection-mark=test passthrough=no
add action=mark-packet chain=prerouting connection-mark=test disabled=no in-interface=wan new-packet-mark=test passthrough=no
不间断更新!