Exec Binding as a cron (several jobs should not be executed at the same time)

I use the exec binding to connect to a few devices and retrieve information from them.
The interval should be the same on all items (10 or 60 Minutes)
But the could not be executed at the exact same time.

Why: I use a tunnel to connect to this remote devices, due to network issues i can only connect to one device at a time.

How can i convert this binding to a cron job which gets executed at different times (or at the same time, but with a few seconds delay)?

Switch ping "ping" {exec="<[/bin/sh@@-c@@ssh root@remote.device ping -c 1 | grep \"packets transmitted\" | sed -e \"s/.*1 received.*/ON/\" -e \"s/.*0 received.*/OFF/\":600000:REGEX((.*))]"}

You need a rule and to use executeCommandLine. Then you can use a ReentrantLock to prevent not than one rule from executing at the same time.

1 Like

Thanks, executecommandline is of course an alternative to the items configured with the exec binding directly
This will expand my rules, but that should be fine.
If i start OpenHAB now, i will receive a few error messages regarding my rule, but it is a false alarm.

How can the
Unable to store Job : 'jobid', because one already exists with this identification.
Error message be avoided?

Thanks for your support.

I don’t know. Do you use a lot of Timers? I’ve seen similar errors when I restart caused by timers that existed before the restart. When OH tries to cancel them they do not exist and generate the error message.

There is no timer in my rule,
but a lot of if statements and a few String items which keep the result of executecomandline("CMD",time)
Could this command be interpreted as a “timer” ?