Community discussions

MikroTik App
 
jaxbluesbass
just joined
Topic Author
Posts: 10
Joined: Mon Dec 05, 2022 3:24 pm

Scripting in SSH

Thu Dec 22, 2022 11:28 am

Hi all i need to run this script over Mikrotik from SSH session:

1- in the first case: I want to create a variable. then I want the next command to be executed taking into account the variable itself.
And change passwd as variable
*************************************************************
@echo off
ssh -t admin@"mikrotik ip" -p 22 –pw "password Mikrotik" |:global myVar "value" | '/user set Main password=$myVar'
pause
**************************************************************

2- in this second case I would like to have the possibility to run the script only - in the lines below I put the example of the created script
********************************************************************************************************************
@echo off
ssh -t admin@"mikrotik ip" -p 22 –pw "password Mikrotik" | /system/script> run number:1
pause
********************************************************************************************************************

Script done as ---------------------------------> | :global myVar "value"| add name=PasswordRecovery source=":user/set Main password=$myVar"

[admin@MikroTik] /system/script> print
Flags: I - invalid
0 name="Passwdsec" owner="Main" policy=ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon
dont-require-permissions=no run-count=0 source= [:execute {/user set Main password=Passwd1}]

is first time that i create script sorry and thanks in advanced
 
zainarbani
Frequent Visitor
Frequent Visitor
Posts: 54
Joined: Thu Jul 22, 2021 9:42 am
Location: Pati, Indonesia

Re: Scripting in SSH

Sat Jan 14, 2023 5:03 am

ssh -t user@host ':global newPw "password123"; /user set user password=$newPw'

ssh -t user@host '/system script add name="Passwdsec" policy=write,policy,password dont-require-permissions=no source="/user set user password=password123"'

ssh -t user@host '/system/script run Passwdsec'
Note:
Don't use a password for ssh, generate a passphrase-less ssh key and put it to your mikrotik.

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot], sstefanov and 17 guests