Community discussions

MikroTik App
just joined
Topic Author
Posts: 1
Joined: Sat May 20, 2017 1:21 am

Auto Billing Report hotspot to email without userman

Fri Jun 02, 2017 1:46 am

#Script based on
#This Script generates a report of prepaid users consumed on a day n, without entering the userman tool
#Send the report to a defaulted email
# You need to configure the sending of mails on the mikrotik router prior to adding the script
# Rb750r2 v.6.39.1
#Version by ajzh
:local date
:local usrname
:local precio
:local tilltime
:local dia
:local status
:local paycode
:local profilecode
:local profile
:local lastseen
:local total
:local body
:local uptime
:local month
:local 1hora
:local 3horas
:local 5horas
:local 1dia
:local 1mes
#define the names of the profiles with which I count in the userman tool, for this example I put generic names, remove the "" and customize in your mikrotik
:set "profile1" 0
:set "profile2" 0
:set "profile3" 0
:set "profile4" 0
:set "profile5" 0
:log info "Start Dayli Report"
:set month [:pick [/system clock get date] 0 3]
:set date [/system clock get date]
:foreach i in=[/tool user-manager user find last-seen!=never] do={
:set lastseen [/tool user-manager user get $i last-seen]
:set dia [:pick $lastseen 0 11]
:if ( [$dia] = [$date] ) do={
:set profile [/tool user-manager user get $i actual-profile]
:if ( [:len $profile] = 0 ) do={
:set usrname [/tool user-manager user get $i username]
:set uptime [/tool user-manager user get $i uptime]
:set paycode [/tool user-manager payment find user=$usrname ]
:set precio [/tool user-manager payment get $paycode price]
:set total ( $total + ($precio/100) )
:set body ( $body . "User : " . $usrname. " Price: ".($precio/100) . " Uptime: " . $uptime .";\n")

#Here counts the number of cards sold, place the generic prices, delete the "" and personalize it in your mikrotik
:if ( [($precio/100)] = "price1" ) do={ :set profile1 ($profile1 + 1)}
:if ( [($precio/100)] = "price2" ) do={ :set profile2 ($profile2 + 1)}
:if ( [($precio/100)] = "price3" ) do={ :set profile3 ($profile3 + 1)}
:if ( [($precio/100)] = "price4" ) do={ :set profile4 ($profile4 + 1)}
:if ( [($precio/100)] = "price5" ) do={ :set profile5 ($profile5 + 1)}
:if ( [$total] = "0" ) do={
:log info "sin ventas $date"
} else={
/tool e-mail send to="some email" from="email account configurated on your mikrotik" subject="Sales Report of the $date" body="Sales Report Date: $date
Total: $total

Example message in spanish
Fichas de profile1 hora=$profile1
Fichas de profile2 horas=$profile2
Fichas de profile3 horas=$profile3
Fichas de profile4 dia=$profile4
Fichas de profile5 mes=$profile5

:log info "email sended"
just joined
Posts: 4
Joined: Thu Oct 08, 2020 6:34 am

Re: Auto Billing Report hotspot to email without userman

Thu Jan 14, 2021 10:35 pm

Good after noin my friend!

I have an issue .I am trying to figure out how to send a message to telegram the total amount of money made in one month on my hotspot. I saw your post and im trying to adapt my script.
My advanced so far is the i already send the message to telegram.
But every time a user logs in i want to send how much did the user spend and have a total amout counter.

User: 12
Price: $5
Total: $0

So the next user that logs in. It has to send

User: 198127
Price: $15
Total: $ 20

This is my advanced so far:
:global aPrice "Price: "
:local cost 5
/tool fetch url="$token/send ... &text=User: $user $aPrice $cost"

If you give me a hint a will appreciate it!

Who is online

Users browsing this forum: Baidu [Spider] and 38 guests