The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My work

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,308 other followers

Delay running a script after restart – MikroTik RouterOS

Posted by jpluimers on 2017/10/24

Start Time special value `startup`

Start Time special value `startup`

There is a special startup value for “Start Time” you can enter which makes it runs once 3 seconds after reboot.

If by then your router isn’t fully “up” yet (i.e. waiting for PPPoE or DHCP network settings), then inside the script you can perform a delay global command as shown in the code fragment from the below forum post.

Don’t you love how people still tend to both repeat themselves and abbreviate stuff even though they have code completion at their disposal?:

{:delay 10};
/log print file=([/system identity get name] . "Log-" . [:pick [/system clock get date] 7 11] . [:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6]); \
/tool e-mail send to="xxx@xxx.com" subject=([/system identity get name] . " Log " . \
[/system clock get date]) file=([/system identity get name] . "Log-" . [:pick [/system clock get date] 7 11] . \
[:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6] . ".txt"); :delay 10; \
/file rem [/file find name=([/system identity get name] . "Log-" . [:pick [/system clock get date] 7 11] . \
[:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6] . ".txt")]; \
:log info ("System Log emailed at " . [/sys cl get time] . " " . [/sys cl get date])

Much easier to read:

{:delay 10};
{
:local currentDate [/system clock get date];
:local fileName ([/system identity get name] . "Log-" . [:pick $currentDate 7 11] . [:pick $currentDate 0 3] . [:pick $currentDate 4 6]);
/log print file=($fileName);
/tool e-mail send to="xxx@xxx.com" subject=([/system identity get name] . " Log " . $currentDate) file=($fileName . ".txt"); :delay 10;
/file remove [/file find name=($fileName . ".txt")];
:log info ("System Log emailed at " . [/system clock get time] . " " . $currentDate)
}

–jeroen

via: [WayBackHow to run script auto after restart – MikroTik RouterOS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: