Community discussions

MikroTik App
 
Zetera
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 52
Joined: Sat Apr 21, 2018 6:57 pm

Commands run perfect in terminal, run perfectly as a script. But refuse to run as a .rsc startup script.  [SOLVED]

Thu Aug 02, 2018 9:18 pm

As stated in the title the following line does not run on reset in a MikroTik

:if ([/system resource get board-name] = "RB750GL" ) do={ :do { certificate import file-name=AddTrustExternalCARoot.CRT passphrase="" }\ on-error={ certificate import file-name=AddTrustExternalCARoot.crt passphrase=""} } else={ :do { certificate import file-name=flash/AddTrustExternalCARoot.CRT passphrase="" }\ on-error={ certificate import file-name=flash/AddTrustExternalCARoot.crt passphrase="" } }

Is there any explanation as to why it runs in the terminal and in a script but not as a startup script? Do one of these piece of logic not apply on startup?
 
DaleNicholsSTG
just joined
Posts: 3
Joined: Fri Aug 03, 2018 1:47 am

Re: Commands run perfect in terminal, run perfectly as a script. But refuse to run as a .rsc startup script.

Fri Aug 03, 2018 2:28 am

First of all, code is easier to read when it is in a code block. I think your code is:
:if ([/system resource get board-name] = "RB750GL" ) do={ :do { certificate import file-name=AddTrustExternalCARoot.CRT passphrase="" }\
  on-error={ certificate import file-name=AddTrustExternalCARoot.crt passphrase=""} } else={ :do { certificate import file-name=flash/AddTrustExternalCARoot.CRT passphrase="" }\
  on-error={ certificate import file-name=flash/AddTrustExternalCARoot.crt passphrase="" } }
or, with better line breaks (I don't think any of the backslashes are required in this version):
:if ([/system resource get board-name] = "RB750GL" ) do={
  :do {
    certificate import file-name=AddTrustExternalCARoot.CRT passphrase="" 
  } on-error={
    certificate import file-name=AddTrustExternalCARoot.crt passphrase=""
  }
} else={
  :do {
    certificate import file-name=flash/AddTrustExternalCARoot.CRT passphrase=""
  } on-error={
    certificate import file-name=flash/AddTrustExternalCARoot.crt passphrase=""
  }
}
I'm far from an expert, but the items I see that might be problems are:
  • certificate instead of /certificate. certificate by itself will only work if you are in the root. You use /system, so I suspect you aren't at the root.
  • Startup scripts typically require a delay. 15 seconds seems to be the standard.
# wait 15 seconds
:delay 15

Note: I've never done anything with certificates, but do they really need to be reinstalled on each startup? And if the file name is case-sensitive, shouldn't you just select one case and use that consistently? It should be possible to find the file (regardless of case or subdirectory), store the filename in a local variable, and then only have one certificate import command.

P.S. You helped me too--I was looking for something like [/system resource get board-name].
 
berzins
just joined
Posts: 10
Joined: Thu Apr 05, 2018 2:46 pm

Re: Commands run perfect in terminal, run perfectly as a script. But refuse to run as a .rsc startup script.

Fri Aug 03, 2018 1:17 pm

I've had issues with scripts starting too fast and then not executing at all.

You could modify the script with a couple of "log warning "failed at 1,2,3 etc" to see where exactly it stops by checking the log.

If it doesn't execute at all on startup, try adding a delay at the start of the script.
:delay 1m;
should be plenty of time for the device to properly boot up.


Should also verify that your scheduler is correctly set.
/system scheduler
add name=importCert on-event=$SCRIPT_NAME$ policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-time=startup
Replace the $SCRIPT_NAME$ with yours and try.