Community discussions

 
Cobusbu
newbie
Topic Author
Posts: 43
Joined: Fri Jan 04, 2008 9:20 am
Location: Cape Town, South Africa

How to implement a delay in a foreach loop

Mon Mar 04, 2013 9:38 pm

Hi all

I need to implement a delay of 10 seconds in a foreach i in loop.

Between every query of the foreach i in loop ten seconds must laps.

The foreach i command is used to send emails and sms's to users about their data usage.

I require a delay in the script in order for email or sms server not to flood.

How may this be done?

Regards
 
User avatar
ohara
Member
Member
Posts: 371
Joined: Mon Jun 13, 2011 11:30 pm
Location: Warsaw

Re: How to implement a delay in a foreach loop

Mon Mar 04, 2013 10:14 pm

try this command, it does nothing for 10 seconds:

ros code

:delay 10s
 
Cobusbu
newbie
Topic Author
Posts: 43
Joined: Fri Jan 04, 2008 9:20 am
Location: Cape Town, South Africa

Re: How to implement a delay in a foreach loop

Tue Mar 05, 2013 7:49 am

Where do I put the delay command in order that a 10 second delay is executed before each query?

The script below is supposed to send sms's to prepaid users based on data used but a sms is only sent to the 1st user then the subsequent sms's don't go through:

{
:local name
:local surname
:local usage
:local bytesin
:local bytesout
:local bytestotal
:local megstotal
:local uptimelimit
:local uptimeused
:local transferlimit
:local transferlimitMB
:local dataremaining
:local cap
:local comment
:local newcomment
:local invoice
:local newinvoice
:local lastmonth
:local monthname
:local lastwarning
:local newmonth
:local newwarning
:local percentage
:local percentile
:local warninglevel
:local warn
:local update
:local email
:local phone
:local server
:local groupname

/tool user-manager user
:foreach i in=[/tool user-manager user find customer="admin"] do={

:set name [get $i first-name]
:set surname [get $i last-name]
:set uptimelimit [get $i uptime]
:set uptimeused [get $i uptime-used]
#There is no transfer limit variable and the value is stored in comment value
:set comment [get $i comment]
:set transferlimit [:pick $comment 5 9]
:set bytesin [get $i download-used]
:set bytesout [get $i upload-used]
:set bytestotal ($bytesin + $bytesout)
:set email [get $i email]
:set phone [get $i phone]

#There is no variable for groupname hence the wireless-enc-key is used to store the group-name variable
#:set groupname [get $i wireless-enc-key]
:set groupname [:pick $comment 0 5]

:if (($groupname = "Prepd") || ($megstotal <40)) do={

:set megstotal ($bytestotal / 1000000)
:set transferlimitMB ($transferlimit)
:set percentage (($megstotal * 100) / $transferlimitMB)
:set dataremaining ($transferlimitMB-$megstotal)

/tool sms send usb3 "$phone" message= "Dear $name $surname you still have $dataremaining MB left until month end"

:log info "Sent sms to $phone $name $surname"

}
}
}
 
User avatar
ohara
Member
Member
Posts: 371
Joined: Mon Jun 13, 2011 11:30 pm
Location: Warsaw

Odp: How to implement a delay in a foreach loop

Tue Mar 05, 2013 8:37 am

Put it anywhere inside your for each statement, for example directly under the :log info command.
 
Cobusbu
newbie
Topic Author
Posts: 43
Joined: Fri Jan 04, 2008 9:20 am
Location: Cape Town, South Africa

Re: How to implement a delay in a foreach loop

Tue Mar 05, 2013 9:44 pm

Thank you very much it worked! :D

Who is online

Users browsing this forum: No registered users and 11 guests