Community discussions

MikroTik App
 
dima1002
Member Candidate
Member Candidate
Topic Author
Posts: 160
Joined: Fri Jan 26, 2018 8:40 pm

Mikrotik script per ssh

Wed Aug 17, 2022 2:27 pm

Hello,
I would like to run the script remotely. Why isn't this working?

ssh root@192.168.1.162 < ./mikrotik_backup.sh

mikrotik_backup.sh
:local filename ([/system identity get name] . "-" . [:pick [/system clock get date] 7 11] . [:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6] . "-" . [:pick [/system clock get time] 0 2] . [:pick [/system clock get time] 3 5]);\
/export file=$filename;\
/system backup save dont-encrypt=yes name=($filename);
Result:
syntax error (line 1 column 266)
expected command name (line 1 column 1)
expected command name (line 1 column 1)
expected command name (line 1 column 1)


This works e.g.
ssh root@192.168.1.162 /system/identity/print
 
afuchs
Frequent Visitor
Frequent Visitor
Posts: 81
Joined: Wed Jul 03, 2019 11:10 am

Re: Mikrotik script per ssh

Wed Aug 17, 2022 2:58 pm

First, Ir´tried to make remote configuration exports some time ago (versiion 6) and found some sifferencess (e.g,"yes" and "no" was replaced with "true" and "false"), so I couldn't copy some pars of the export right back to the router (e.g. if I had deleted some entries from a address list. So you should check this.
This even happened is i sun a script on the router ('/export file=[/system identity get name]') over ssh. (same script different output).

Than there are some difference between the commnds on the router (terminal) or over ssh. I am not up to date with this, so you should test your script step for step.
 
dima1002
Member Candidate
Member Candidate
Topic Author
Posts: 160
Joined: Fri Jan 26, 2018 8:40 pm

Re: Mikrotik script per ssh

Thu Aug 25, 2022 11:38 am

cat ./system.sh | ssh -p22 test@10.99.0.187

system.sh
#! /bin/bash
/user group add name=system policy=local,telnet,ssh,ftp,reboot,read,write,policy,test,winbox,password,web,sniff,sensitive,api,romon,dude,rest-api
/user add name=sys address=10.99.0.0/16,192.168.111.0/24' group=sys password='TEST1TEST!TEST'
/user ssh-keys import public-key-file=test.pub user=sys
Failure:
expected end of command (line 1 column 17)
syntax error (line 1 column 28)
input does not match any value of user

The script always has problems with spaces, how can I solve this?

Who is online

Users browsing this forum: Bing [Bot], dpa, GoogleOther [Bot], nichky, rextended and 16 guests