Community discussions

MikroTik App
 
sjfp
just joined
Topic Author
Posts: 7
Joined: Fri Mar 04, 2022 2:10 pm

Run Script after Re-Boot

Wed Apr 27, 2022 5:20 pm

Is it possible to run a script once after reboot ??
 
holvoetn
Forum Guru
Forum Guru
Posts: 5478
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Run Script after Re-Boot

Wed Apr 27, 2022 5:27 pm

Once as in really only once and then never again, not even subsequent reboots ?
Don't think so without other scripting to change things.

But it is possible to have a script run after each reboot.
Use scheduler and set start-time=startup

See also https://help.mikrotik.com/docs/display/ROS/Scheduler
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Run Script after Re-Boot

Wed Apr 27, 2022 7:35 pm

Yes,

1st case, only one time after reboot, everytime the machine reboot:
/system scheduler
add name=everytimeonreboot  start-time=startup interval=0s \
    on-event=":delay 20s;\r\n/system script run <SCRIPTNAME>"

2nd case, only one time after reboot, but just for next reboot only:
/system scheduler
add name=onlyonetimeonreboot  start-time=startup interval=0s \
    on-event=":delay 20s;\r\n/system script run <SCRIPTNAME>\r\n/system scheduler disable onlyonetimeonreboot"
for execute again on boot, simply enable again the scheduler
 
holvoetn
Forum Guru
Forum Guru
Posts: 5478
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Run Script after Re-Boot

Wed Apr 27, 2022 7:37 pm

As I said, additional scripting to disable things.
Nicely done !
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Run Script after Re-Boot

Wed Apr 27, 2022 7:39 pm

3rd case, only one time after reboot, but just for next reboot only, self-destruction scheduler:
/system scheduler
add name=selfdestructionscheduler start-time=startup interval=0s \
    on-event=":delay 20s;\r\n/system script run <SCRIPTNAME>\r\n/system scheduler remove [find where name=selfdestructionscheduler]"
for execute again on boot, you must add again the scheduler.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12001
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Run Script after Re-Boot

Wed Apr 27, 2022 7:41 pm

As I said, additional scripting to disable things.
Nicely done !
Thanks ;)

Who is online

Users browsing this forum: No registered users and 12 guests