Hi everyone.
Something doing my head in tonight and I am new to MikroTik (which I love), but this bit has me stumped so this is a bit of a noob question.
I have written and can run the following script either in Winbox or via the terminal (/sys script run emailonreboot-script) and it sends the e-mail after 70 seconds. What I want it to do is simply send an e-mail to my Linux support logging system to give me a heads-up if any of the customer MikroTiks reboot:
I noted a while back in some documentation that you must leave the Schedule set to all zeros for a script to be used on boot up only scenario, ie run just the once.
So using Winbox I have set the following:
Name: emailonreboot
Start date: May/08/2014
Start time: 14:53:54
Interval: 00:00:00
On event:
/sys script run emailonreboot-script
Owner: admin (greyed out)
Policy: reboot
Run count: 0
Next run:
And the bottom of the box shows “enabled”
I tried selecting various policy options (at one part it seemed start spamming me, so something is not quite selected correctly and I would assume just ‘reboot’ policy is needed?
Not sure about the start time and dates but given I started playing with this earlier today, I assume it has just put in these date/times.
This is a MikroTik RB951G-2HnD, routerOS is 5.26
The router reboots happily but never sends any e-mail so I am assuming I am missing something given the script runs perfectly if I execute it directly.
Start date/time is the problem. Set time to zeroes and date as old as possible - 1.1.1970 or so. The reason is that it takes some time to set the correct time after startup, therefore your script is never run.
Thanks c0d3rSh3ll but the script is running fine from Winbox and from the command line. It just isn’t running from the scheduler.
Thanks jarda, I did as you suggested and believe the setup to be closer to what is needed now.
I reset the date to “Jan/01/1970” and set the Start Time to “startup” and rebooted the router. Still no luck - it did count that it ran it once in the overall reboots that I subsequently did but I never received anything.
It has reset its start date to yesterday again (May/08/2014) since the subsequent reboots.
I also changed delay to “180s” to give it three minutes to think about things - again this only works when I run the script directly.
I have included a jpg screenshot of the setup just in case you spot something I haven’t done.
I have also setup a daily script just to ‘check-in’ with my log system as I do will all of my beloved customer Linux servers, so I know things should be up each morning - this seems to work ok as I did set the interval to three minutes and I get check-ins every three minutes, so the scheduler is working, just my reboot bit seems to have some kind of noobie bug
Thanks Jarda, the last bit you advised has worked and ran just a few minutes ago after I set it and rebooted the router. Now to roll it out to all of my MikroTik babies
So setting all the policies to being ‘ticked’ and just putting the script name (emailonreboot-script in my case) in the “On event” section without the “/sys scripts run” bit worked perfectly.