前段時間去朋友公司看他們的GuestWIF密碼是按公司名稱加上年月日的方式,會自動更改以爲這個有點意思,這樣能夠防止把公司辦公的WIFI密碼泄露出去。shell
具體步驟:api
1:添加腳本以下bash
# months array :local months ("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec") # get Date :local ds [/system clock get date] # convert name of month to number :local month [ :pick $ds 0 3 ]; :local mm ([ :find $months $month -1 ] + 1); :if ($mm < 10) do={ :set mm ("0" . $mm); } # set $ds to format YYYY-MM-DD :set ds ([:pick $ds 7 11] . $mm . [:pick $ds 4 6]) :log info "date format : $ds sss" # 這樣最後的密碼是 XXX20161010 這樣的格式 /interface wireless security-profiles set 1 wpa2-pre-shared-key="XXX$ds" # 這裏的 1 是 guest 的配置文件序號
2:添加計劃任務less
/system scheduler add interval=1d name="update wifi pass" on-event="/system script run AutoUpdateGuest Passwd" policy=ftp,reboot,read,write,policy,test,winbox,password,sniff,sensitive,api start-date=oct/20/ 2016 start-time=01:00:00
最主要如何獲得格式化的日期。其它沒什麼。腳本和正常的shell不同。ide