I am trying to make a script that counts the number of trial users online and writes it to a file. I want it to count the number of users every hour, and add the result to a new line in the file (to be used as a CSV file). However, I think I am doing the re-write wrong, as the file includes the file name of every file on the router as well as the results.
How should I be handling this re-writing?
Code: Select all
#Initialising Variables
#Varible to set the frommaddress to the systemname@some.server
:global system [/system identity get name]
:global time [/system clock get time]
:global date [/system clock get date]
#Variable for user name
:local userno
#Variable for text file contents
:local filetext
:local headings
:set headings ("Date,Time,Users\n")
#check if file already exists, if not create it
:local check [/file find name=usersperhourreport.txt]
:if ( $check = "" ) do= {
#Create file
/file print file=usersperhourreport
#Set the headings for the columns (\n for new line)
/file set usersperhourreport.txt contents="$headings\n"
}
#Pull details out of user list and assign to relevant variables accordingly
:set userno [/ip hotspot active print count-only]
#Insert the values to the text file
:set filetext ("$date,$time,$userno\n")
/file set usersperhourreport.txt contents=([/file get [/file find name=usersperhourreport.txt] contents] . "\n$filetext");
:delay 5
/tool e-mail send to="me@some.server" subject=($system . " Users per Hour Usage Report") body="Attached is the hourly usage report for $system made at $time on $date \nNote: The attached file is a comma seperated value file, simply import into a spreadsheet" from=libraryreports@some.server file=usersperhourreport.txt server=999.999.999.999
:log info "Report Emailed"
Here is the output of the file
Code: Select all
# dec/11/2008 8:15: 4 by RouterOS 3.13
# software id = EQZ1-ZXT
#
# NAME TYPE SIZE CREATION-TIME
0 libhs directory 1024 dec/10/2008 13:41:21
1 libhs/img directory 1024 dec/10/2008 11:15:06
2 libhs/lv directory 1024 dec/10/2008 11:15:06
3 libhs/alogin.html .html file 1342 dec/10/2008 11:15:06
4 libhs/aplus.png .png file 18448 dec/10/2008 11:15:06
5 libhs/error.html .html file 938 dec/10/2008 11:15:06
6 libhs/errors.txt .txt file 3719 dec/10/2008 11:15:06
7 libhs/img/isla... .png file 27875 dec/10/2008 11:15:06
8 libhs/img/logo... .png file 4317 dec/10/2008 11:15:06
9 libhs/img/Thum... .db file 6144 dec/10/2008 11:15:06
10 libhs/login.html .html file 6594 dec/10/2008 13:41:21
11 libhs/logout.html .html file 1886 dec/10/2008 11:15:06
12 libhs/lv/alogi... .html file 1352 dec/10/2008 11:15:06
13 libhs/lv/error... .txt file 3853 dec/10/2008 11:15:06
14 libhs/lv/login... .html file 3504 dec/10/2008 11:15:06
15 libhs/lv/logou... .html file 1916 dec/10/2008 11:15:06
16 libhs/lv/radve... .html file 1537 dec/10/2008 11:15:06
17 libhs/lv/statu... .html file 2860 dec/10/2008 11:15:06
18 libhs/md5.js .js file 7218 dec/10/2008 11:15:06
19 libhs/radvert.... .html file 1543 dec/10/2008 11:15:06
20 libhs/redirect... .html file 223 dec/10/2008 11:15:06
21 libhs/scrc_lib... .jpg file 26691 dec/10/2008 11:15:06
22 libhs/status.html .html file 3202 dec/10/2008 11:15:06
dec/11/2008,08:17:43,0
dec/11/2008,08:20:47,0
dec/11/2008,08:20:53,0
Thanks