How to enable user using script when it is disabled

Hi friends,

I have one CCR 1009 device. In that i have a user 1 & user 2 with full access.

User2 is disabling user1. But i need a script which will check in a particular time interval for disable. if that(user1) is disable need to re-enable using that script.

Kindly help. Thanks in advance.

:local userName "userName"
:local disabledStatus []

:set disabledStatus [user get [find name=$userName] disabled]

:if ($disabledStatus) do={ 
    /user set $userName disabled=no
    :log info "User $userName is enabled"
}

for time interval, simply use the scheduler to launch the control at a given time

/user enable [find where name="user1" and disabled=yes]

if you want log also when the user is enabled (and not everytime if is enabled or not)

:local user "user1"
/user
:if ([:len [find where name=$user and disabled=yes]] > 0) do={
    enable [find where name=$user]
    :log info "User $user enabled again"
}

if you want continuosly check, but activate on given time interval (do not overlap with midnight!!!)
without logging

:local user     "user1"
:local timefrom "14:00:00"
:local timeto   "18:00:00"

:local now [/sys clock get time]
:if ( ([:totime $timefrom] < $now) and ($now < [:totime $timeto]) ) do={
    /user enable [find where name=$user and disabled=yes]
}

with logging

:local user     "user1"
:local timefrom "14:00:00"
:local timeto   "18:00:00"

:local now [/sys clock get time]
:if ( ([:totime $timefrom] < $now) and ($now < [:totime $timeto]) ) do={
    /user
    :if ([:len [find where name=$user and disabled=yes]] > 0) do={
        enable [find where name=$user]
        :log info "User $user enabled again"
    }
}