Community discussions

MikroTik App
 
alixviral
just joined
Topic Author
Posts: 7
Joined: Tue Apr 23, 2024 12:11 pm

"my script does not work" in v7.10

Fri Apr 26, 2024 6:21 pm

please help me to make it work i cant make a script so can you modifi this for me to make it work in v7.10 i cant get [/system clock get date]
:local dateint do={
    :local montharray { "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" };
    :local days [ :pick $d 4 6 ];
    :local month [ :pick $d 0 3 ];
    :local year [ :pick $d 7 11 ];
    :local monthint ([ :find $montharray $month ]);
    :local month ($monthint + 1);
    :if ( [len $month] = 1) do={
        :local zero "0";
        :return [:tonum ("$year$zero$month$days")];
    } else={
        :return [:tonum ("$year$month$days")];
    }
};

:local timeint do={
    :local hours [ :pick $t 0 2 ];
    :local minutes [ :pick $t 3 5 ];
    :return ($hours * 60 + $minutes);
};

:local date [ /system clock get date ];
:local time [ /system clock get time ];
:local today [$dateint d=$date] ;
:local curtime [$timeint t=$time] ;

:foreach i in [ /ppp secret find where profile="1m" ] do={
    :local comment [ /ppp secret get $i comment];
    :local name1 [ /ppp secret get $i name];
    :local gettime [:pick $comment 12 20];
    :if ([:pick $comment 3] = "/" and [:pick $comment 6] = "/") do={
        :local expd [$dateint d=$comment] ;
        :local expt [$timeint t=$gettime] ;
        :if (($expd < $today and $expt < $curtime) or ($expd < $today and $expt > $curtime) or ($expd = $today and $expt < $curtime)) do={
            /ppp secret set profile=Expired $i ;
            /ppp active remove [find where name=$name1];
        }
    }
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12032
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: "my script does not work" in v7.10

Fri Apr 26, 2024 7:24 pm

viewtopic.php?t=196072

stop spam on forum

the script is really shitty, this is what you want, but still shitty.
:local dateint do={
    :local days [ :pick $d 8 10 ];
    :local month [ :pick $d 5 7 ];
    :local year [ :pick $d 0 4 ];
    :return [:tonum ("$year$month$days")];
};
 
alixviral
just joined
Topic Author
Posts: 7
Joined: Tue Apr 23, 2024 12:11 pm

Re: "my script does not work" in v7.10

Fri Apr 26, 2024 7:53 pm

viewtopic.php?t=196072

stop spam on forum

the script is really shitty, this is what you want, but still shitty.
:local dateint do={
    :local days [ :pick $d 8 10 ];
    :local month [ :pick $d 5 7 ];
    :local year [ :pick $d 0 4 ];
    :return [:tonum ("$year$month$days")];
};
im so sorry for spam but im noob can you put this with the script and thanks (i dont know anything about scripting)
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3614
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: "my script does not work" in v7.10

Fri Apr 26, 2024 8:04 pm

It's just hard to help when it bit unclear what the script is trying to do...

There is also [:timestamp] which will give you an int of the time (in nanoseconds since 1970). Also time types can be compared without converting to an int.
 
alixviral
just joined
Topic Author
Posts: 7
Joined: Tue Apr 23, 2024 12:11 pm

Re: "my script does not work" in v7.10

Fri Apr 26, 2024 8:11 pm

It's just hard to help when it bit unclear what the script is trying to do...

There is also [:timestamp] which will give you an int of the time (in nanoseconds since 1970). Also time types can be compared without converting to an int.
can i get the time online from https://worldtimeapi.org/api/timezone/Asia/Baghdad
and what is the script for it ?
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3614
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: "my script does not work" in v7.10

Fri Apr 26, 2024 8:19 pm

Not easily in v7.10, but in latest stable this work:
{
:local bgwtime [:deserialize from=json ([/tool/fetch url=https://worldtimeapi.org/api/timezone/Asia/Baghdad as-value output=user]->"data")]  
# debug to show output
:put $bgwtime
# print one value from the worldtimeapi.org data
:put ($bgwtime->"day_of_week")

# get it's unixtime as a int
:local bgwunix [:tonum ($bgwtime->"unixtime")]
:put $bgwunix
}
abbreviation=3;client_ip=x.x.x.x;datetime=2024-04-26T20:18:47.951963+03
:00;day_of_week=5;day_of_year=117;dst=false;dst_from=;dst_offset=0;dst_until=;
raw_offset=10800;timezone=Asia/Baghdad;unixtime=1714151927;utc_datetime=2024-0
4-26T17:18:47.951963+00:00;utc_offset=03:00:00;week_number=17

5

1714151927

Who is online

Users browsing this forum: No registered users and 13 guests