Community discussions

MikroTik App
 
ivdok
just joined
Topic Author
Posts: 1
Joined: Tue Mar 16, 2021 2:23 pm

"Expected end of command" before on-error

Tue Mar 16, 2021 2:33 pm

Hi! I'm trying to idempotently create new system user via scripting, but for some reason I'm getting stupid error that makes no sense.
:if ( [/user group find where name=oxidized] ) do={
  :log info ("Group oxidized exists, bailing...")
} else={
  :log info ("Provisioning oxidized user: oxidized...")
  /user group add name=oxidized policy=read,ssh
} on-error={ :log info ("User provisioning error!") };
Why does script fail immediately? https://wiki.mikrotik.com/wiki/Manual:S ... _statement doesn't show that I need to do more than :if () do={} else={}, so what gives? Really annoying.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: "Expected end of command" before on-error

Tue Mar 16, 2021 5:13 pm

You are adding a user group, not a user.

To add a user.
/user add name=test group=full 
If the goal is to create a group, you need to change the code to make on-error work.
on-error needs to be started with do, and if any command innside fails, code in on-error runs.
:do {
	:if ( [/user group find where name=oxidized] ) do={
		:log info ("Group oxidized exists, bailing...")
	} else={
		:log info ("Provisioning oxidized user: oxidized...")
		/user group add name=oxidized policy=read,ssh}
} on-error={ :log info ("User provisioning error!")
}

Who is online

Users browsing this forum: alexantao and 19 guests