Uptime script

Hello All,

I am attempting to write a ROS script where based on the system uptime I need to turn up (disable=no) an interface. The only thing that seems to be eluding me is actually getting the uptime value into a variable I can work with in the script. Is there a specific “get” that I can get just the uptime? So far I have not stumbled on the correct syntax for that, and the manual has not been too helpful.

If there is no elegant and simple solution, then plan B would be to parse the output of “/ system resource print” to get the information.

Any advice would be greatly appreciated.

Thanks!

You can save uptime to a variable with:

:local upTime [/system resource get uptime]

You can test it in the terminal with:

{
:local upTime [/system resource get uptime]
:put $upTime                               
}

(starting and ending brackets are for testing in the terminal when using local variables and can be removed in the final script)

Any news?

Thanks for the reply, I am certain I tried “/system resource get uptime” before I posted but I must have had some error in the syntax or it was one of those things where the error was so obvious I could not see it. Anyhow it works now, and here is what I came up with.

Delay needed to get everything up and running after boot, otherwise script starts too quickly, and fails for some unknown reason.

: delay 1m
:global upSeconds “1”
while ($upSeconds < 3600)
do={ \

All this is just to convert XwYdHH:MM:SS to seconds.

:local upTime [/system resource get uptime]
:local weeks [:pick $upTime 0 [:find $upTime “w”]]
:set upTime [:pick $upTime ([:find $upTime “w”]+1) [:len $upTime]]
:local days [:pick $upTime 0 [:find $upTime “d”]]
:set upTime [:pick $upTime ([:find $upTime “d”]+1) [:len $upTime]]
:local hours [:pick $upTime 0 [:find $upTime “:”]]
:set upTime [:pick $upTime ([:find $upTime “:”]+1) [:len $upTime]]
:local minutes [:pick $upTime 0 [:find $upTime “:”]]
:set upTime [:pick $upTime ([:find $upTime “:”]+1) [:len $upTime]]
:local seconds $upTime
:global upSeconds [(($weeks604800)+($days86400)+($hours3600)+($minutes60)+$seconds)]
:delay 1m
}

Now the stuff I wanted to do.

What was wrong with

:delay 1h

Nothing, but it is in association with a netwatch, on a wireless link. If the router was just re-booted I want to wait an hour before I do some housekeeping, and if the link just flaps then I’m doing other stuff.

???
schedule on startup:

disable all not wanted netwatch
delay 1h
re-enable all netwatch.

done.

3 instructions only…

Yes, I suppose I could have done as you describe, and then have some netwatch items that get disabled and others enabled and hour after a re-boot but when the netwatch item is enabled it tests the condition and it executes the event based on the up/down condition. So I still needed to test to see if the change in state up/down was due to a reboot, or just network condition.. I guess in the end this was my approach to fulfill the request, Boss is happy.. Happy Boss = life is good.

confuse fix