adding a lot of ppp secret on mikrotik script

hi ppl. i need help. how can i add 700 ppp secret on mikrotik. they are in one txt file, which has this format:
username,password,local_address,remote_address,profile,service
i can upload that file on mikrotik FTP, and scrpit, which i need, must read that file, and create ppp secret, using data from that file. can someone help me. version of my mikrotik is 2.9.27.thanks
PS: sorry, my english is very bad :frowning: i hope so, that they understand, what i need.

Before anything, why 700 ppp secrets.. sounds like you’d be better off with a small radius server running.

and if so, why not just import them into the user-manager?

ok, im network administrator in one scool, and i have on mikrotik one pppoe server. each of student have one ppp secret to connecting on pppoe server. each of student has own local address, remote address, username and password.

I assume that information per user is written in one line.
This script will parse file and convert each line it finds to array. From that array data can be easily extracted and passed as parameter to any command:

:global content [/file get [/file find name=filename.txt] contents] ;
:global contentLen [ :len $content ] ;

:local lineEnd 0;
:local line "";
:local lastEnd 0;


:do {
       :set lineEnd [:find $content "\r\n" $lastEnd ] ;
       :set line [:pick $content 0 $lineEnd] ;
       :set lastEnd $lineEnd ;

       :local tmpArray [:toarray $line] ;
       # here you can add ppp secret
       # if this is the format -> username,password,local_address,remote_address,profile,service
       /ppp secret add name=[:pick $tmpArray 0] password=[:pick $tmpArray 1] .... and so on
} while ($lineEnd < $contentLen)

This script don’t perform any error checkings:
*) if data is not in this format → username,password,local_address,remote_address,profile,service - script will fail

this script is not working at me :frowning::frowning:

:global content [/file get [/file find name=accaunts.txt] contents] ;
:global contentLen [ :len $content ] ;

:local lineEnd 0;
:local line "";
:local lastEnd 0;


:do {
       :set lineEnd [:find $content "\r\n" $lastEnd ] ;
       :set line [:pick $content 0 $lineEnd] ;
       :set lastEnd $lineEnd ;
       :local tmpArray [:toarray $line] ;
         /ppp secret add name=[:pick $tmpArray 0] password=[:pick $tmpArray 1] local address=[:pick $tmpArray 2] remote address=[:pick $tmpArray 3] profile=[:pick $tmpArray 4] service=[:pick $tmpArray 5];
} while ($lineEnd < $contentLen)

what is wrong there???
file has name accaunts.txt and i write in it this:
kolins,sifra,10.10.1.10,192.168.1.10,students,pppoe

when i start this script, it’s nothing happening :frowning::frowning:
can someone help me??? please!!

:global content [/file get [/file find name=test.txt] contents] ;
:global contentLen [ :len $content ] ;

:global lineEnd 0;
:global line "";
:global lastEnd 0;

:do {
       :set lineEnd [:find $content "\r\n" $lastEnd ] ;
       :set line [:pick $content $lastEnd $lineEnd] ;
       :set lastEnd ( $lineEnd + 2 ) ;

       :local tmpArray [:toarray $line] ;
       :if ( [:pick $tmpArray 0] != "" ) do={
              :put $tmpArray;
              /ppp secret add name=[:pick $tmpArray 0] password=[:pick $tmpArray 1] local-address=[:pick $tmpArray 2] remote-address=[:pick $tmpArray 3] profile=[:pick $tmpArray 4] service=[:pick $tmpArray 5];
       }
} while ($lineEnd < $contentLen)

This code works for sure, tested myself.
Note that at the en of each line you must have “\r\n” sequence ( this is default windows newline ); If you have other format modify 9-th line of script according to what you need.

Test file can be created easily:
/file print file=“test.txt”
/file set test.txt contents=“kolins,sifra,10.10.1.1,192.168.1.1,students,pppoe\r\naaa,bbb,1.1.1.1,2.2.2.2,students,pppoe\r\n”

sorry, it’s not working again :frowning: :frowning: :frowning:
when i type this command, i get error message. u can see it on pic.

[admin@STSZav] > /file set accaunti.txt contents="kolins,sifra,10.10.1.1,192.168.1.1,students,pppoe\r\naaa,bbb,1.1.1.1,2.2.2.2,s
tudents,pppoe\r\n"
no such command or directory (set)
[admin@STSZav] >

my_file.JPG
error1.JPG

You are geting this error probably because you are on 2.9.xx
/file set is available only in 3.0

Also in 3.0 scripting is a lot more improved


you can write file in notepad and then upload to router via ftp


Also it is not recommended to use so many ppp secrets on integrated accounting system.
Use external RADIUS server or Mikrotik UserManager.

OK. I have Mikrotik 2.9.27. Can u help me that i make this configuration: Mikrotik PPPOE SERVER + MIKROTIK USER MANAGER. Is possible that combination on only ONE Mikrotik? Sorry, if i intrude :frowning:

Upgrade to latest version, also you will have to get level 6 license if you have more than 10 active sessions

i already have level 6 :wink:

How to Download/ Install and create subscriber:
http://wiki.mikrotik.com/wiki/User_Manager/Getting_started

UserManager and ppp:
http://wiki.mikrotik.com/wiki/User_Manager/PPP_Example

i’m again there, with same problem :frowning: i have mikrotik v3.13 lvl4, but this script didn’t work on my mikrotik :frowning: i have test.txt file, and when i run script nothing happens :frowning: now i need same script for add users in user manager, not secrets. i can’t change this scipt, because it’s not work :frowning: can sameone help me? thanks.

Hi,

It is very easy only if you have a linux machine available. The following script can help you out.

FPATH="/path/to/dir"
FILE="raw-data-file"
NEW="newfile.rsc

echo "/ppp secret" >> $FPATH/$NEW
cat $FILE | while read users
do

UID=`echo $users | cut-d, -f1`
PASS=`echo $users | cut-d, -f2`
LOC_ADD=`echo $users | cut-d, -f3`
REM_ADD=`echo $users | cut-d, -f4
PROFILE=`echo $users | cut-d, -f5`
SERVICE=`echo $users | cut-d, -f6`

echo "add name=\"$UID\" password=$PASS local-address=$LOC_ADD remote-address=$REM_ADD service=$SERVICE profile=$PROFILE " >> $FPATH/$NEW

done

I do most of my work with linux scripts. So its very easy.