| View previous topic :: View next topic |
| Author |
Message |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Wed May 20, 2015 11:55 pm Post subject: bind cron weekly help |
|
|
Need a process is active:
monday to thursday
from 02:01AM to 6PM every 20 minutes
from 6:01PM to 02:00AM the next day every 10 minutes
Fridays, Saturdays and Sundays
from 4:01AM to 7PM every 15min
from 7:01PM to 4:00AM the next day every 5min
(please see EDIT)
I read the eggdrop documentation but did not understand how it works.
The proc:
| Quote: | | bind cron - {?????} advertise |
| Code: |
proc advertise { nick uhost hand chan arg } {
global advertisetext status1 topicount
if {($status1 != "ON") || ($topicount == 0 )} { return
} else {
if {![file exists radiochans1.txt]} { return
} else {
set fname "radiochans1.txt"
set fp [open $fname "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"]
foreach chan [channels] {
if {$lines != "" } {
if {([lsearch -exact [string tolower $lines] [string tolower $chan]] != -1)} { putserv "privmsg $chan :$advertisetext" }
}
}
}
}
} |
If you can explain how it is done, so the next codes I will modify without help, I have 10 more processes to change.
EDIT:
Reviewing the consultation, I made an inconsistency between Sunday and Monday:
Monday must be:
from 04:01AM to 6PM every 20 minutes
from 6:01PM to 02:00AM (tuesday)the next day every 10 minutes
Tuesday and Wednesday
from 02:01AM to 6PM every 20 minutes
from 6:01PM to 02:00AM the next day every 10 minutes
Thursday
from 02:01AM to 6PM every 20 minutes
from 6:01PM to 04:00AM (friday)the next day every 10 minutes
Fridays, Saturdays and Sundays
from 4:01AM to 7PM every 15min
from 7:01PM to 4:00AM the next day every 5min _________________ If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks  |
|
| Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1175
|
Posted: Fri May 22, 2015 9:00 am Post subject: Re: bind cron weekly help |
|
|
| juanamores wrote: |
...
I read the eggdrop documentation but did not understand how it works. ...
...
If you can explain how it is done, so the next codes I will modify without help, I have 10 more processes to change.
...
|
The eggdrop tcl-commands.doc does not go into depth on this. It simply says that to refer to the crontab manual.
What I do:
Google for terms such as, "crontab examples".
You will find lots of help that way. With the various specifics that you require, I think you will find ways to accomplish them, with different lines for each in your crontab.
I hope this helps. _________________ For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia ! |
|
| Back to top |
|
 |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Fri May 22, 2015 9:10 am Post subject: |
|
|
I did so, not if you work well, I have not had time opportunity to test it.
If there is a better way to do it without many if ... I appreciate the help.
Please, see if logical and properly bind cron command syntax.
| Code: | bind cron - {* * * * *} cron:semanal
proc cron:semanal {min hour day month weekday} {
if {![file exists radiochans1.txt]} {
set fs [open radiochans1.txt w]
puts $fs ""
close $fs
} else {
set fname "radiochans1.txt"
set fp [open $fname "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"]
foreach chan [channels] {
if {$chan == "" } continue
if {[botonchan $chan] != 1} {break;return}
}
if {[string trimleft $min 0] == 00 && [string trimleft $hour 0] == 00 && [string trimleft $weekday 0] == 1} { bind cron - {*/20 * 00-18 * 1} advertise }
if {[string trimleft $min 0] == 00 && [string trimleft $hour 0] == 18 && [string trimleft $weekday 0] == 1} { bind cron - {*/10 * 18-24 * 1} advertise }
if {[string trimleft $min 0] == 00 && [string trimleft $hour 0] == 00 && [string trimleft $weekday 0] == 2} { bind cron - {*/20 * 00-18 * 2} advertise }
if {[string trimleft $min 0] == 00 && [string trimleft $hour 0] == 18 && [string trimleft $weekday 0] == 2} { bind cron - {*/10 * 18-24 * 2} advertise }
if {[string trimleft $min 0] == 00 && [string trimleft $hour 0] == 02 && [string trimleft $weekday 0] == 3} { bind cron - {*/20 * 02-18 * 3} advertise }
if {[string trimleft $min 0] == 00 && [string trimleft $hour 0] == 18 && [string trimleft $weekday 0] == 3} { bind cron - {*/10 * 18-24 * 3} advertise }
if {[string trimleft $min 0] == 00 && [string trimleft $hour 0] == 02 && [string trimleft $weekday 0] == 4} { bind cron - {*/20 * 02-18 * 4} advertise }
if {[string trimleft $min 0] == 00 && [string trimleft $hour 0] == 18 && [string trimleft $weekday 0] == 4} { bind cron - {*/10 * 18-24 * 4} advertise }
if {[string trimleft $min 0] == 00 && [string trimleft $hour 0] == 00 && [string trimleft $weekday 0] == 5} { bind cron - {*/20 * 00-19 * 5} advertise }
if {[string trimleft $min 0] == 00 && [string trimleft $hour 0] == 19 && [string trimleft $weekday 0] == 5} { bind cron - {*/10 * 19-24 * 5} advertise }
if {[string trimleft $min 0] == 00 && [string trimleft $hour 0] == 00 && [string trimleft $weekday 0] == 6} { bind cron - {*/20 * 00-19 * 6} advertise }
if {[string trimleft $min 0] == 00 && [string trimleft $hour 0] == 19 && [string trimleft $weekday 0] == 6} { bind cron - {*/10 * 19-24 * 6} advertise }
if {[string trimleft $min 0] == 00 && [string trimleft $hour 0] == 00 && [string trimleft $weekday 0] == 7} { bind cron - {*/20 * 00-19 * 7} advertise }
if {[string trimleft $min 0] == 00 && [string trimleft $hour 0] == 19 && [string trimleft $weekday 0] == 7} { bind cron - {*/10 * 19-24 * 7} advertise }
}
} |
EDIT:
I had doubts, I did not know how to put 18 - 23:59, because I think it does not allow the syntax of this command.
i.e:
| Code: | | if {[string trimleft $min 0] == 00 && [string trimleft $hour 0] == 18 && [string trimleft $weekday 0] == 1} { bind cron - {*/10 * 18-24 * 1} advertise } |
If I put 18-00 and would be in the next day.
EDIT2: The more I read about it the less I understand.
The example below, it means the advertise command will run every 10 minutes between 18 and 23:59 every Monday ?
| Code: | | bind cron - {0-59/10 18-23 * * 1} advertise |
=======================================
If my reasoning is correct, the examples below would be fine.
Sunday every 10 min 0:00 - 03:59
| Code: | | if {[string trimleft $min 0] == 00 && [string trimleft $hour 0] == 0 && [string trimleft $weekday 0] == 0} { bind cron - {0-59/10 0-3 * * 0} advertise } |
Sunday every 20 min 4:00 - 18:59
| Code: | | if {[string trimleft $min 0] == 00 && [string trimleft $hour 0] == 0 && [string trimleft $weekday 0] == 0} { bind cron - {0-59/20 4-18 * * 0} advertise } |
Sunday every 10 min 19:00 - 23:59
| Code: | | if {[string trimleft $min 0] == 00 && [string trimleft $hour 0] == 19 && [string trimleft $weekday 0] == 0} { bind cron - {0-59/10 19-23 * * 0} advertise } |
======================================= _________________ If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks  |
|
| Back to top |
|
 |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Fri May 22, 2015 10:26 pm Post subject: Re: bind cron weekly help |
|
|
| willyw wrote: |
What I do:
Google for terms such as, "crontab examples".
|
This issue is very confusing, the examples I saw on Google for the days used interchangeably: 0-6 or 1-7 (1 digit) or Mon Tue etc ..
But in the debuggin the code returns me to day with 2 digits and you can not use abbreviations.
00 or 07 Sunday
01 Monday
etc ....
I could only test is that the syntax of the command if I put before, are wrong.
This is the correct syntax according to testing.
| Code: | | if {$min == "47" && $hour == "01" && $weekday == "06"} { |
Examples are wrong, not working properly. _________________ If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks  |
|
| Back to top |
|
 |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Sat May 23, 2015 10:42 pm Post subject: Fixed |
|
|
I found a solution, it is not very "orthodox", but is all I could to do with my limited knowledge of Tcl.
I share it to other users who may have the same doubts and I close this topic if no better ideas.
| Code: | bind cron - {* * * * *} cron:semanal
proc cron:semanal {min hour day month weekday} {
global canal_admin
if {![file exists radiochans1.txt]} {
return
} else {
set fname "radiochans1.txt"
set fp [open $fname "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"]
set onch1 0
foreach chan [channels] {
if {([lsearch -glob -ascii -nocase $lines $chan] != -1) && ([onchan $::botnick $chan])} { set onch1 [expr {$onch1 + 1}] }
}
if {$onch1 == 0} return
if {$min == "00" && $hour == "04" && $weekday == "00"} {unbinds;bind cron - {*/20 * * * *} advertise }
if {$min == "00" && $hour == "18" && $weekday == "00"} {unbinds;bind cron - {*/10 * * * *} advertise }
if {$min == "00" && $hour == "00" && $weekday == "01"} {unbinds;bind cron - {*/20 * * * *} advertise }
if {$min == "00" && $hour == "18" && $weekday == "01"} {unbinds;bind cron - {*/10 * * * *} advertise }
if {$min == "00" && $hour == "00" && $weekday == "02"} {unbinds;bind cron - {*/20 * * * *} advertise }
if {$min == "00" && $hour == "18" && $weekday == "02"} {unbinds;bind cron - {*/10 * * * *} advertise }
if {$min == "00" && $hour == "00" && $weekday == "03"} {unbinds;bind cron - {*/20 * * * *} advertise }
if {$min == "00" && $hour == "18" && $weekday == "03"} {unbinds;bind cron - {*/10 * * * *} advertise }
if {$min == "00" && $hour == "00" && $weekday == "04"} {unbinds;bind cron - {*/20 * * * *} advertise }
if {$min == "00" && $hour == "18" && $weekday == "04"} {unbinds;bind cron - {*/10 * * * *} advertise }
if {$min == "00" && $hour == "04" && $weekday == "05"} {unbinds;bind cron - {*/20 * * * *} advertise }
if {$min == "00" && $hour == "18" && $weekday == "05"} {unbinds;bind cron - {*/10 * * * *} advertise }
if {$min == "00" && $hour == "04" && $weekday == "06"} {unbinds;bind cron - {*/20 * * * *} advertise }
if {$min == "00" && $hour == "18" && $weekday == "06"} {unbinds;bind cron - {*/10 * * * *} advertise }
}
}
proc unbinds { } {
foreach ele [binds cron] {
foreach {type flags name hits proc} $ele {
if {[string match "advertise" $proc]} {
unbind $type $flags $name $proc
break
}
}
}
}
|
I used unbind command because to put range time, not getting the desired results, by joining the previous timer to the next.
I tried:
| Code: | | bind cron -|- {*/10 00-04 * * *} advertise |
At 04:00 the process stopped , but continued to run advertising for 10 minutes (queue) and joined to the next.
The process is activated this way:
Sundays 04:00-18:00 every 20 min
Sundays 18:00-23:59 every 10 min
From Monday to Thursday from 00:00-18:00 every 20 min
From Monday to Thursday from 18:00-23:59 every 10 min
Friday 00:00-04:00 every 20 min
Friday 04:00-18:00 every 10 min
Friday 18:00-23:59 every 10 min
Saturday from 00:00-04:00 every 10 min
Saturday from 04:00-18:00 every 20 min
Saturday from 18:00-23:59 every 10 minutes until Sunday at 04:00 am returning every 20 min. _________________ If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks  |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Sun May 24, 2015 4:03 am Post subject: |
|
|
What about
| Code: |
bind cron - {*/20 4 * * 0,5,6} advertise
bind cron - {*/20 0 * * 1,2,3,4} advertise
bind cron - {*/10 18 * * *} advertise
|
Not 100% sure so give this a try.
And in the advertise function do that unbind of the previous cron binds. _________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Sun May 24, 2015 3:49 pm Post subject: |
|
|
| caesar wrote: | What about
| Code: |
bind cron - {*/20 4 * * 0,5,6} advertise
bind cron - {*/20 0 * * 1,2,3,4} advertise
bind cron - {*/10 18 * * *} advertise
|
Not 100% sure so give this a try.
And in the advertise function do that unbind of the previous cron binds. |
The idea would be not to use | Code: | | bind cron - {* * * * *} cron:semanal |
and do unbind in the same process advertise ?
Something like that ?:
| Code: | bind cron - {*/20 4 * * 0,5,6} advertise
bind cron - {*/20 0 * * 1,2,3,4} advertise
bind cron - {*/10 18 * * *} advertise
proc advertise { nick uhost hand chan arg } {
unbinds
#more stuff....#
}
proc unbinds { } {
foreach ele [binds cron] {
foreach {type flags name hits proc} $ele {
if {[string match "advertise" $proc]} {
unbind $type $flags $name $proc
break
}
}
}
}
|
This does not unbind me the same cron I'm activating?
How I can make the code distinguishes the previous cron binds and not unbind the current cron I'm activating?
I thought of something to distinguish by the number of hits, if value of hits is zero, it is the current process and performed a break and return in the process unbinds.
It might work or is there a better way to do this?
| Code: | proc unbinds { } {
foreach ele [binds cron] {
foreach {type flags name hits proc} $ele {
if {($proc eq "advertise") && ($hits == 0)} { break;return }
if {($proc eq "advertise") && ($hits != 0)} {
unbind $type $flags $name $proc
break
}
}
}
} |
EDIT:
My idea will not work for the following reason:
The first time the "unbinds" and "advertise" process run smoothly.
But the second time the number of hits of that process will have value 1 and unbind the current bind cron. _________________ If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks  |
|
| Back to top |
|
 |
juanamores Master
Joined: 15 Mar 2015 Posts: 317
|
Posted: Tue May 26, 2015 1:18 am Post subject: Fixed |
|
|
I fixed.
I returned to cron:weekly but with much less lines and working properly.
| Code: | bind cron - {* * * * *} cron:weekly
proc cron:weekly {min hour day month weekday} {
if {($min == "50" && $hour == "23") && ($weekday == "01" || $weekday == "02" || $weekday == "03" || $weekday == "04")} \
{unbinds;bind cron - {*/10 0 * * 1,2,3,4} advertise}
if {($min == "50" && $hour == "03") && ($weekday == "00" || $weekday == "05" || $weekday == "06")} \
{unbinds;bind cron - {*/20 4 * * 0,5,6} advertise }
if {($min == "50" && $hour == "17") && ($weekday == "01" || $weekday == "02" || $weekday == "03" || $weekday == "04")} \
{unbinds;bind cron - {*/10 18 * * *} advertise }
}
proc unbinds { } {
foreach ele [binds cron] {
foreach {type flags name hits proc} $ele {
if {[string match "advertise" $proc]} {
unbind $type $flags $name $proc
putlog "UNBIND $type $flags $name $proc"
break
}
}
}
} |
_________________ If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks  |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|