因工作需要,wifi密码需定期修改,为了不影响绩效,搞了一个自动脚本。
网上找了好久都没有找到适合自己的,ros查了官方文档好像没有随机数函数,就自己想办法计算出一个随机数。根据日期和cpu使用率计算出一个随机数了,取中间8位用作密码,理论上每次生成的都会不一样。
:local months ("jan","feb","mar","apr", "may","jun","jul","aug","sep","oct","nov","dec")
:local ds [/system clock get date]
:local month [:pick $ds 0 3 ];
:local mm ([:find $months $month -1 ] + 1);
:if ($mm < 10) do={:set mm ("0" . $mm);}
:set ds ([:pick $ds 7 11] . $mm . [:pick $ds 4 6])
:local d ([:pick [/system clock get time] 0 2] .[:pick [/system clock get time] 3 5].[:pick [/system clock get time] 6 8])
:local mf [:pick $aaa 5 6]
:local dk ([/system resource get cpu-load]+5)
:local jj ([:pick $ds 2 8] * $ds * 1024999*$d*$dk)
:local pass [:pick $jj 3 11]
:log info $dk
:log info $pass
/caps-man security set [/caps-man security find name="密码配置文件名"] passphrase=$pass
把上面的放到脚本里面,每次运行就能得到一个8位数字密码
再到计划里面加入计划,按需设置运行就能实现定期修改密码了。
下面配置邮件发送,每次修改密码后,把新的密码发送到邮箱。
#定义邮件变量
:local from "发件邮箱"
:local user "发件帐号"
:local password "密码"
:local to "收件地址"
:local cc ""
:local address "服务器ip
#把密码发送到邮箱
/tool e-mail send server=($address) port=25 cc=($cc) from=($from) user=($user) password=($password) to=($to) subject="WiFi password update" body=("$pass")
}