Community discussions

MUM Europe 2020
 
User avatar
airstream
Member Candidate
Member Candidate
Topic Author
Posts: 188
Joined: Fri Feb 03, 2006 6:33 am
Location: New Zealand

End Of Month Script 2.9.51

Mon Mar 24, 2008 2:00 pm

Hi All I am trying to adapt a script from the Wiki to work on production 2.9.51.

This "nightly" script runs every night :
:global found
 
 /system script run monthend
 
 :if ([$found] = true) do={ /system script run resetcount ; :log info "Automatic EOM Usermanager counter reset"}
 :if ([$found] = false) do={ /system script run  usagewarnings ; :log info "Usage Warning Script triggered" }
the Monthend script:
:local date
 :local day
 :local month
 :local year
 :local yeardiv
 :local yearmult
 :local leapyear
 :local lastday
 :global found 
  
 :set date [system clock get date]
 :set month [:pick $date 0 3]
 :set day [:pick $date 4 6]
 :set year [:pick $date 7 11]
 
 :set yeardiv ($year / 4)
 :set yearmult ($yeardiv * 4)
 
 :if ([$yearmult] = $year) do={ :set leapyear true } else={ :set leapyear false }
 :if ([$month] = jan) do={ :set lastday 31 }
 :if ([$month] = feb) do={ 
        :if ($leapyear = true) do={ :set lastday 29 }
        :if ($leapyear = false) do={ :set lastday 28 } }
 :if ([$month] = mar) do={ :set lastday 31 } 
 :if ([$month] = apr) do={ :set lastday 30 }
 :if ([$month] = may) do={ :set lastday 31 }
 :if ([$month] = jun) do={ :set lastday 30 }
 :if ([$month] = jul) do={ :set lastday 31 }
 :if ([$month] = aug) do={ :set lastday 31 }
 :if ([$month] = sep) do={ :set lastday 30 }
 :if ([$month] = oct) do={ :set lastday 31 }
 :if ([$month] = nov) do={ :set lastday 30 }
 :if ([$month] = dec) do={ :set lastday 31 }
 :if ([$lastday] = $day) do={ :set found true } else={ :set found false }
The monthend script should run and give the "found" variable a value of either true or false after being called from line two of the nightly script. When returning to the nightly script there seems to be no value in 'found', none of the if statements run anything from "nightly"

I know this was noted to work on v3 betas, can someone direct me to how to alter this script for 2.9?

Cheers
Keep tryin' its bound to work!!
-----
-----
ROOT@COSMOS> Reality.sys corrupted -- Reboot Universe (Y/N)?
>_
 
User avatar
jordantrx
Long time Member
Long time Member
Posts: 505
Joined: Tue Oct 23, 2007 8:58 pm
Location: WAY upstate NY

Re: End Of Month Script 2.9.51

Mon Mar 24, 2008 2:35 pm

Hi All I am trying to adapt a script from the Wiki to work on production 2.9.51.

This "nightly" script runs every night :
:global found
 
 /system script run monthend
 
 :if ([$found] = true) do={ /system script run resetcount ; :log info "Automatic EOM Usermanager counter reset"}
 :if ([$found] = false) do={ /system script run  usagewarnings ; :log info "Usage Warning Script triggered" }
the Monthend script:
:local date
 :local day
 :local month
 :local year
 :local yeardiv
 :local yearmult
 :local leapyear
 :local lastday
 :global found 
  
 :set date [system clock get date]
 :set month [:pick $date 0 3]
 :set day [:pick $date 4 6]
 :set year [:pick $date 7 11]
 
 :set yeardiv ($year / 4)
 :set yearmult ($yeardiv * 4)
 
 :if ([$yearmult] = $year) do={ :set leapyear true } else={ :set leapyear false }
 :if ([$month] = jan) do={ :set lastday 31 }
 :if ([$month] = feb) do={ 
        :if ($leapyear = true) do={ :set lastday 29 }
        :if ($leapyear = false) do={ :set lastday 28 } }
 :if ([$month] = mar) do={ :set lastday 31 } 
 :if ([$month] = apr) do={ :set lastday 30 }
 :if ([$month] = may) do={ :set lastday 31 }
 :if ([$month] = jun) do={ :set lastday 30 }
 :if ([$month] = jul) do={ :set lastday 31 }
 :if ([$month] = aug) do={ :set lastday 31 }
 :if ([$month] = sep) do={ :set lastday 30 }
 :if ([$month] = oct) do={ :set lastday 31 }
 :if ([$month] = nov) do={ :set lastday 30 }
 :if ([$month] = dec) do={ :set lastday 31 }
 :if ([$lastday] = $day) do={ :set found true } else={ :set found false }
The monthend script should run and give the "found" variable a value of either true or false after being called from line two of the nightly script. When returning to the nightly script there seems to be no value in 'found', none of the if statements run anything from "nightly"

I know this was noted to work on v3 betas, can someone direct me to how to alter this script for 2.9?

Cheers
You have to debug it using different symbols. The best thing you can i do is is go into sys scripts edit monthend source then from there see where the problem is and keep changing it untill it sits right with that version of OS. I beleive you will have to change the :if's n () [ ] and all of that.. Just look at the 2.51 scrips and compare and see what you should probibly change it to to get it to work. GOOD luck
~Agricultural WISP "ZONE"~ Beware of oncoming cattle and dont hit the farmer!!! I need to ask him about using his silo for an AP first"~

*Automated Billing Installer* http://wiki.mikrotik.com/wiki/AutomatedBilling Built by Krige ;-)
 
User avatar
airstream
Member Candidate
Member Candidate
Topic Author
Posts: 188
Joined: Fri Feb 03, 2006 6:33 am
Location: New Zealand

Re: End Of Month Script 2.9.51

Wed Mar 26, 2008 2:20 pm

In these billing scripts it refers to a comment in usermanager. however I cannot find a comment field!

Any pointer on this?
Keep tryin' its bound to work!!
-----
-----
ROOT@COSMOS> Reality.sys corrupted -- Reboot Universe (Y/N)?
>_
 
User avatar
jordantrx
Long time Member
Long time Member
Posts: 505
Joined: Tue Oct 23, 2007 8:58 pm
Location: WAY upstate NY

Re: End Of Month Script 2.9.51

Wed Mar 26, 2008 4:09 pm

In these billing scripts it refers to a comment in usermanager. however I cannot find a comment field!

Any pointer on this?
You acces comment feild by doing this

/tool user-manager user> print
/tool user-manager user> edit 1 comment
/tool user-manager user> edit 0 comment


And so on and so forth. let me know if you have any problems. I use this script in my network. see below... (thanks krige). :-) -Jordan
~Agricultural WISP "ZONE"~ Beware of oncoming cattle and dont hit the farmer!!! I need to ask him about using his silo for an AP first"~

*Automated Billing Installer* http://wiki.mikrotik.com/wiki/AutomatedBilling Built by Krige ;-)
 
User avatar
airstream
Member Candidate
Member Candidate
Topic Author
Posts: 188
Joined: Fri Feb 03, 2006 6:33 am
Location: New Zealand

Re: End Of Month Script 2.9.51

Mon Mar 31, 2008 2:10 am

Thanks for your tips, I have now got these scripts to run nicely. Also kudos to krige - your scripts have opened the world of mikrotik scripting to me, I am now working on a script to run with the userman package much like the warningemail script but it changes the speeds of the user relevant to the percentage of the users cap

ie auto throttle back to 64k when it is > 99% of cap and back to a higher speed if the same value is < 99%.

If I can get this to work = nice :wink:

Although the throttle rates per user are held in UM like this:
rate-limit=" 128k/270k 0/0 0/0 0/0 7"
. so therefore, that whole " 128k/270k 0/0 0/0 0/0 7" must be loaded in a variable, then split etc.

Anybody aware of how to get the Rate limit (RX and TX) fields individually from the UM?
Keep tryin' its bound to work!!
-----
-----
ROOT@COSMOS> Reality.sys corrupted -- Reboot Universe (Y/N)?
>_
 
User avatar
jordantrx
Long time Member
Long time Member
Posts: 505
Joined: Tue Oct 23, 2007 8:58 pm
Location: WAY upstate NY

Re: End Of Month Script 2.9.51

Mon Mar 31, 2008 3:44 pm

Thanks for your tips, I have now got these scripts to run nicely. Also kudos to krige - your scripts have opened the world of mikrotik scripting to me, I am now working on a script to run with the userman package much like the warningemail script but it changes the speeds of the user relevant to the percentage of the users cap

ie auto throttle back to 64k when it is > 99% of cap and back to a higher speed if the same value is < 99%.

If I can get this to work = nice :wink:

Although the throttle rates per user are held in UM like this:
rate-limit=" 128k/270k 0/0 0/0 0/0 7"
. so therefore, that whole " 128k/270k 0/0 0/0 0/0 7" must be loaded in a variable, then split etc.

Anybody aware of how to get the Rate limit (RX and TX) fields individually from the UM?
Yea it is a very good script. I have learned alot about script when debugging it. I created a script to send out a global message to all users in usermanager, sending e-mails to all the users lettin them know there will be downtime on such and such a date because of upgrades or replacement of equipment etc etc./.. -Jordan
~Agricultural WISP "ZONE"~ Beware of oncoming cattle and dont hit the farmer!!! I need to ask him about using his silo for an AP first"~

*Automated Billing Installer* http://wiki.mikrotik.com/wiki/AutomatedBilling Built by Krige ;-)
 
User avatar
jordantrx
Long time Member
Long time Member
Posts: 505
Joined: Tue Oct 23, 2007 8:58 pm
Location: WAY upstate NY

Re: End Of Month Script 2.9.51

Mon Mar 31, 2008 3:47 pm

FYI, if you have the scripts all working on 2.50 ROS you should put that in the wikie or get a hold of Krige and have him possibly update his wikie with the version 2.50 Automated billing script... talk to Normis he may know better what to do? maybe you could earn a licenes off from it... Not sure anyways - over and out
~Agricultural WISP "ZONE"~ Beware of oncoming cattle and dont hit the farmer!!! I need to ask him about using his silo for an AP first"~

*Automated Billing Installer* http://wiki.mikrotik.com/wiki/AutomatedBilling Built by Krige ;-)
 
thinair
newbie
Posts: 26
Joined: Thu Aug 23, 2007 3:43 pm

Re: End Of Month Script 2.9.51

Mon Jun 09, 2008 12:51 am

Is there any update on the Usage Warning script? I can't make the script work on 2.9.51 :(
 
User avatar
jordantrx
Long time Member
Long time Member
Posts: 505
Joined: Tue Oct 23, 2007 8:58 pm
Location: WAY upstate NY

Re: End Of Month Script 2.9.51

Mon Jun 09, 2008 4:15 pm

Is there any update on the Usage Warning script? I can't make the script work on 2.9.51 :(
That is because it was built for the 3.0 ROS. However i beleive airstream is editing it to work with 2.9.51 so maybe he can provide you with the edited version of the Auotmated billing script. -Jordan
~Agricultural WISP "ZONE"~ Beware of oncoming cattle and dont hit the farmer!!! I need to ask him about using his silo for an AP first"~

*Automated Billing Installer* http://wiki.mikrotik.com/wiki/AutomatedBilling Built by Krige ;-)
 
User avatar
airstream
Member Candidate
Member Candidate
Topic Author
Posts: 188
Joined: Fri Feb 03, 2006 6:33 am
Location: New Zealand

Re: End Of Month Script 2.9.51

Wed Jun 11, 2008 3:37 am

Hi all, I do have edited working scripts roughly based on Krige's code for both v2.9 and v3. They include some/all the features from Krige's billing script with added bits for on the fly capping "speed adjusting" of TX and RX speeds, automated email to customers that have hit their datacap or different stages that you can preset (say 5 Gib)etc. Automatic resetting of caps (throttles etc) and data used on the any particular day of the month etc.

Are these worthy of wiki? Does Krige want them for publish?
Keep tryin' its bound to work!!
-----
-----
ROOT@COSMOS> Reality.sys corrupted -- Reboot Universe (Y/N)?
>_
 
dainen
newbie
Posts: 38
Joined: Tue Jul 05, 2005 12:33 pm
Location: Byron Bay, Australia
Contact:

Re: End Of Month Script 2.9.51

Wed Jun 11, 2008 7:51 am

Definitely worthy of a wiki
 
User avatar
jordantrx
Long time Member
Long time Member
Posts: 505
Joined: Tue Oct 23, 2007 8:58 pm
Location: WAY upstate NY

Re: End Of Month Script 2.9.51

Wed Jun 11, 2008 3:32 pm

Hi all, I do have edited working scripts roughly based on Krige's code for both v2.9 and v3. They include some/all the features from Krige's billing script with added bits for on the fly capping "speed adjusting" of TX and RX speeds, automated email to customers that have hit their datacap or different stages that you can preset (say 5 Gib)etc. Automatic resetting of caps (throttles etc) and data used on the any particular day of the month etc.

Are these worthy of wiki? Does Krige want them for publish?
Either give krige the V2.9.X version of the script so he can update it to his wiki. Or you can post it on your own wiki and maybe get a free license for editing the script to 2.9.X. -Jordan
~Agricultural WISP "ZONE"~ Beware of oncoming cattle and dont hit the farmer!!! I need to ask him about using his silo for an AP first"~

*Automated Billing Installer* http://wiki.mikrotik.com/wiki/AutomatedBilling Built by Krige ;-)
 
majsta
just joined
Posts: 3
Joined: Fri Aug 22, 2008 8:28 pm

Re: End Of Month Script 2.9.51

Sun Aug 24, 2008 7:14 pm

Where can i find version for 2.9.x?
 
User avatar
omega-00
Forum Guru
Forum Guru
Posts: 1167
Joined: Sat Jun 06, 2009 4:54 am
Location: Australia
Contact:

Re: End Of Month Script 2.9.51

Tue Sep 02, 2008 3:42 pm

For anyone thats interested, I also started my mikrotik scripting with the AutomatedBilling one, and have since made one that doesn't require the usermanager but has all the basic functionality that is required.

Regarding the end of month thing, I ended up making mine just run every hour and modified the month-end script to allow this and only run the monthly reports on the first hour of each new month (1am on the first day of a month)

see - http://wiki.mikrotik.com/wiki/Automated ... sermanager

Who is online

Users browsing this forum: No registered users and 12 guests