Community discussions

MikroTik App
 
tabate47
Long time Member
Long time Member
Topic Author
Posts: 510
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Command Line Reset with External Run After Reset File?

Sun May 29, 2016 8:00 pm

Is it possible to run a run after reset file not physically located in the mikrotik folder, but rather on your pc?

I would like to connect to the router via serial cable, and do a command line reset with no defaults, and run a setup script located on my pc.

Can this be done?

/system reset-configuration no-defaults=yes skip-backup=yes ?????????????
 
pe1chl
Forum Guru
Forum Guru
Posts: 10216
Joined: Mon Jun 08, 2015 12:09 pm

Re: Command Line Reset with External Run After Reset File?

Sun May 29, 2016 10:44 pm

You can issue that command and then just paste the config into your conection with the serial port.
 
tabate47
Long time Member
Long time Member
Topic Author
Posts: 510
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Command Line Reset with External Run After Reset File?

Sun May 29, 2016 10:58 pm

You mean just paste the text of the script into the console via serial?
 
pe1chl
Forum Guru
Forum Guru
Posts: 10216
Joined: Mon Jun 08, 2015 12:09 pm

Re: Command Line Reset with External Run After Reset File?

Mon May 30, 2016 11:06 am

You mean just paste the text of the script into the console via serial?
Yes, that should work.
Or use an upload function of the terminal program (not X/Y/Z modem of course, but plain upload).
 
tabate47
Long time Member
Long time Member
Topic Author
Posts: 510
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Command Line Reset with External Run After Reset File?

Mon May 30, 2016 1:41 pm

What would the command line for uploading a file from your pc to the mikrotik look like?
 
pe1chl
Forum Guru
Forum Guru
Posts: 10216
Joined: Mon Jun 08, 2015 12:09 pm

Re: Command Line Reset with External Run After Reset File?

Mon May 30, 2016 2:15 pm

What would the command line for uploading a file from your pc to the mikrotik look like?
That depends on the operating system that you use and the serial console tool you use with it.
 
User avatar
Deantwo
Member
Member
Posts: 331
Joined: Tue Sep 30, 2014 4:07 pm

Re: Command Line Reset with External Run After Reset File?

Mon May 30, 2016 3:43 pm

What would the command line for uploading a file from your pc to the mikrotik look like?
RouterOS has both a FTP server and a FTP client built in.

To use the FTP client you can use the "/tool fetch" command.
See: wiki.mikrotik.com/wiki/Manual:Tools/Fetch

Otherwise you can connect to the router's FTP server if it is enabled and upload a file to it.
If the file is named "*.auto.rsc", RouterOS will automatically execute the script inside it.
See: wiki.mikrotik.com/wiki/Manual:Configuration_Management#Importing_Configuration

The "/system reset-configuration" command can also be set to import a script file after reseting.
See: wiki.mikrotik.com/wiki/Manual:Configuration_Management#Configuration_Reset

Do however remember that importing a script automatically in anyway will fail if the script contains any errors.

Possibly the easiest way to do what you are asking, is to place your file on an FTP server and fetch it in the router's CLI before you reset it.
An example:
# Download configuration file.
/tool fetch mode=ftp address=192.168.1.200 src-path="YourScript.rsc" dst-path="YourScript.rsc"

# If download was successful, reset the configuration and force it to execute the script file.
/system reset-configuration no-defaults=yes skip-backup=yes run-after-reset="YourScript.rsc"
 
tabate47
Long time Member
Long time Member
Topic Author
Posts: 510
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Command Line Reset with External Run After Reset File?

Mon May 30, 2016 6:54 pm

For an exact example, let's say the file you want to upload to the router via serial is called file.rsc. You are using a windows pc, and file.rsc is located on your desktop. The pc's IP address is 192.168.156.

What would that code look like?
 
User avatar
Deantwo
Member
Member
Posts: 331
Joined: Tue Sep 30, 2014 4:07 pm

Re: Command Line Reset with External Run After Reset File?

Mon May 30, 2016 9:00 pm

let's say the file you want to upload to the router via serial
I don' think you can actually transfer the file through the serial connection.
 
tabate47
Long time Member
Long time Member
Topic Author
Posts: 510
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Command Line Reset with External Run After Reset File?

Tue May 31, 2016 3:43 am

I'm trying to paste this script into the router via the serial connection, and I keep getting errors.

What am I doing wrong?
/ip pool
add name=pool1 ranges=192.168.1.2-192.168.1.254
/ip dhcp-server
add address-pool=pool1 disabled=no interface=ether2 lease-time=3d name=server1
/ip address
add address=192.168.1.1/24 interface=ether2 network=192.168.1.0
/ip dhcp-server network
add address=192.168.1.0/24 dns-server=192.168.1.1 gateway=192.168.1.1
/ip dns
set allow-remote-requests=yes
/ip firewall nat
add action=masquerade chain=srcnat out-interface=ether1
/ip dhcp-client
add default-route-distance=0 dhcp-options=hostname,clientid disabled=no interface=ether1
 
User avatar
Deantwo
Member
Member
Posts: 331
Joined: Tue Sep 30, 2014 4:07 pm

Re: Command Line Reset with External Run After Reset File?

Tue May 31, 2016 8:07 am

I'm trying to paste this script into the router via the serial connection, and I keep getting errors.
Maybe this question is super stupid, but what is the errors you are getting? And at which lines?
 
tabate47
Long time Member
Long time Member
Topic Author
Posts: 510
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Command Line Reset with External Run After Reset File?

Tue May 31, 2016 8:24 am

They are different each time. Can someone try it and see if they are also getting errors?

Please connect via serial and paste it in after a reset.
 
User avatar
Deantwo
Member
Member
Posts: 331
Joined: Tue Sep 30, 2014 4:07 pm

Re: Command Line Reset with External Run After Reset File?

Tue May 31, 2016 8:32 am

They are different each time. Can someone try it and see if they are also getting errors?
So, let me just guess.
  • "No such item"
  • "Item already exists"
Am I close? I can only really guess while I am not at my desk.

Even if they are different every time, it would help A LOT to know what the errors are and which commands are giving the errors.

Even better if you just copy-paste the console screen here.
 
tabate47
Long time Member
Long time Member
Topic Author
Posts: 510
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Command Line Reset with External Run After Reset File?

Tue May 31, 2016 8:57 am

no, those are not the errors. I do a complete reset before pasting.

I'm not in my lab so I can't get you the error info right now.

Please give it a try and see what I mean.
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26368
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: Command Line Reset with External Run After Reset File?

Tue May 31, 2016 9:00 am

If you don't post the actual errors, nobody can help. Hint: the error actually explains what is wrong. Seriously.
 
tabate47
Long time Member
Long time Member
Topic Author
Posts: 510
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Command Line Reset with External Run After Reset File?

Tue May 31, 2016 9:02 am

I understand. I can't do it until tomorrow. I am asking if someone can try it to see if they get any errors.
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26368
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: Command Line Reset with External Run After Reset File?

Tue May 31, 2016 9:07 am

The above script will only work on a router with zero configuration. Most people here do have already a pool named "pool1" so they will get errors, same as you probably
 
tabate47
Long time Member
Long time Member
Topic Author
Posts: 510
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Command Line Reset with External Run After Reset File?

Tue May 31, 2016 9:12 am

I only run the script after executing this command:

/system reset-configuration no-defaults=yes skip-backup=yes
 
User avatar
Deantwo
Member
Member
Posts: 331
Joined: Tue Sep 30, 2014 4:07 pm

Re: Command Line Reset with External Run After Reset File?

Tue May 31, 2016 9:14 am

Another stupid question, what router model are you using?
The router does have two ethernet ports, right?
 
User avatar
Deantwo
Member
Member
Posts: 331
Joined: Tue Sep 30, 2014 4:07 pm

Re: Command Line Reset with External Run After Reset File?

Tue May 31, 2016 9:17 am

/ip pool
add name=pool1 ranges=192.168.1.2-192.168.1.254
/ip dhcp-server
add address-pool=pool1 disabled=no interface=ether2 lease-time=3d name=server1
/ip address
add address=192.168.1.1/24 interface=ether2 network=192.168.1.0
/ip dhcp-server network
add address=192.168.1.0/24 dns-server=192.168.1.1 gateway=192.168.1.1
/ip dns
set allow-remote-requests=yes
/ip firewall nat
add action=masquerade chain=srcnat out-interface=ether1
/ip dhcp-client
add default-route-distance=0 dhcp-options=hostname,clientid disabled=no interface=ether1
There, I can run it all without any errors.
This is however using the terminal in WinBox, but I would be surprised if it is any different on the serial connection.
 
tabate47
Long time Member
Long time Member
Topic Author
Posts: 510
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Command Line Reset with External Run After Reset File?

Tue May 31, 2016 9:24 am

The terminal in winbox is different. It works for me every time. It only gets the errors via serial.
 
tabate47
Long time Member
Long time Member
Topic Author
Posts: 510
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Command Line Reset with External Run After Reset File?

Tue May 31, 2016 9:26 am

The router is a CCR1009-8G-1S
 
User avatar
Deantwo
Member
Member
Posts: 331
Joined: Tue Sep 30, 2014 4:07 pm

Re: Command Line Reset with External Run After Reset File?

Tue May 31, 2016 9:29 am

The terminal in winbox is different. It works for me every time. It only gets the errors via serial.
Ah, I don't believe you mentioned this before.
In that case, the error messages would help even more.

I don't really have access to a router with serial, so I can't test it.
But I was wondering, wouldn't it be easier to just replace the default configuration using Netinstall?
See: wiki.mikrotik.com/wiki/Manual:Netinstall
 
tabate47
Long time Member
Long time Member
Topic Author
Posts: 510
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Command Line Reset with External Run After Reset File?

Tue May 31, 2016 9:34 am

I need to connect to a tech in the field from a remote location via team viewer and set up the router. That's why I need the serial setup.
 
pe1chl
Forum Guru
Forum Guru
Posts: 10216
Joined: Mon Jun 08, 2015 12:09 pm

Re: Command Line Reset with External Run After Reset File?

Tue May 31, 2016 10:42 am

Maybe it is a flow control or overrun problem... I would use 9600 baud.
 
tabate47
Long time Member
Long time Member
Topic Author
Posts: 510
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Command Line Reset with External Run After Reset File?

Tue May 31, 2016 5:37 pm

How do you switch to 9600? Is it as simple as changing it in putty, or do you have to do something to the router?
 
tabate47
Long time Member
Long time Member
Topic Author
Posts: 510
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Command Line Reset with External Run After Reset File?

Tue May 31, 2016 6:12 pm

Here is the error:

[admin@MikroTik] > /ip pool
[admin@MikroTik] /ip pool> add name=pool1 ranges=192.168.1.2-192.168.1.254
[admin@MikroTik] /ip pool> /ip dhcp-server
[admin@MikroTik] /ip dhcp-server> add address-pool=pool1 disabled=no interface=ether2 lease-time=3d name=server1
[admin@MikroTik] /ip dhcp-server> /ip address
[admin@MikroTik] /ip address> add address=192.168.1.1/24 interface=ether2 network=192.168.1.0
[admin@MikroTik] /ip address> /ip dhcp-client
[admin@MikroTik] /ip dhcp-client> add interfac
expected end of command (line 1 column 5)
[admin@MikroTik] /ip dhcp-client>
 
pe1chl
Forum Guru
Forum Guru
Posts: 10216
Joined: Mon Jun 08, 2015 12:09 pm

Re: Command Line Reset with External Run After Reset File?

Tue May 31, 2016 8:08 pm

It looks like it is losing input due to high speed.
You should be able to set it to 9600 in the terminal program and it should auto-detect the baudrate.
 
tabate47
Long time Member
Long time Member
Topic Author
Posts: 510
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Command Line Reset with External Run After Reset File?

Tue May 31, 2016 8:10 pm

I think you are right.

How do you set the baud rate in terminal?
 
pe1chl
Forum Guru
Forum Guru
Posts: 10216
Joined: Mon Jun 08, 2015 12:09 pm

Re: Command Line Reset with External Run After Reset File?

Tue May 31, 2016 8:34 pm

I think you are right.

How do you set the baud rate in terminal?
Depends on your terminal program. In Putty you can set it when you make a connection.
 
tabate47
Long time Member
Long time Member
Topic Author
Posts: 510
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Command Line Reset with External Run After Reset File?

Tue May 31, 2016 8:36 pm

If I try to set it to 9600 in putty it will not connect.

Do you have to make changes to the router first?

If so, what are they?
 
tabate47
Long time Member
Long time Member
Topic Author
Posts: 510
Joined: Wed Mar 13, 2013 5:23 am
Location: Los Angeles

Re: Command Line Reset with External Run After Reset File?

Wed Jun 01, 2016 6:52 am

I think I have confirmed that you cannot add this script because the baud rate is too high.

Is there another way to get this script on the router via the serial cable, or another way to put a simple setup on the router via the serial so I can further set it up on the network?
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26368
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: Command Line Reset with External Run After Reset File?

Wed Jun 01, 2016 1:25 pm

System Reset doesn't delete files. Why can't you put the file on the device while it is still connected to Ethernet ? Serial Cable is not appropriate to transmit such things

Who is online

Users browsing this forum: GoogleOther [Bot], holvoetn, johnb175a, llamajaja, patrikg, woland and 66 guests