Community discussions

 
User avatar
theWISP
Member Candidate
Member Candidate
Topic Author
Posts: 111
Joined: Fri Sep 12, 2008 4:13 am
Contact:

Help with script to find / in identity and replace with -

Mon Aug 04, 2014 8:49 pm

Hey Folks,

Any help would be appreciated. We currently have a script that uploads the most recent backup of our routeros devices to an offsite ftp location weekly. The problem is all of our ptp devices have an identity consisting of a "/". This breaks the ftp script, and really is bad practice anyhow. We have a couple hundred devices on our infrastructure side that need this done, so I would like to script it. Would anyone have the time to give me a quick script to find "/" in an Identity and replace it with a "-"?

I have done a lot of scripting, but am out of practice and am so crammed for time that I thought maybe I could lean on the mikrotik community for a quick solution.

Thanks!
Adam J
 
psamsig
Member Candidate
Member Candidate
Posts: 161
Joined: Sun Dec 06, 2009 1:36 pm
Location: Denmark

Re: Help with script to find / in identity and replace with

Tue Aug 05, 2014 8:52 am

/system identity {
    :local orgIdentity [get name]
    :local newIdentity
    :for i from=0 to=([:len $orgIdentity] -1) do={
        :if ([:pick $orgIdentity $i] = "/") do={
            :set newIdentity "$newIdentity-"
        } else={
            :set newIdentity ($newIdentity . [:pick $orgIdentity $i])
        }
    }
    :if ($orgIdentity != $newIdentity) do={
        set name=$newIdentity
    }
}
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 2944
Joined: Tue Feb 25, 2014 12:49 pm
Location: Capalbio, Tuscany, Italy

Re: Help with script to find / in identity and replace with

Tue Aug 05, 2014 11:03 am

:local myname value=[/system identity get value-name=name];
:local newname value="";
:if ([:find $myname "/" -1] > 0) do={
 :for i from=0 to=([:len $myname] -1) step=1 do={
  :local actualchar value=[:pick $myname $i];
  :if ($actualchar = "/") do={ :set actualchar value="-" };
  :set newname value=($newname.$actualchar);
 }
 /system identity set name=$newname;
};
I'm Italian, not English. Sorry for my imperfect grammar.
 
User avatar
theWISP
Member Candidate
Member Candidate
Topic Author
Posts: 111
Joined: Fri Sep 12, 2008 4:13 am
Contact:

Re: Help with script to find / in identity and replace with

Tue Aug 05, 2014 7:12 pm

Thanks a ton guys!!!! You saved me a few hours of tinkering.

Who is online

Users browsing this forum: No registered users and 10 guests