Hint: to make sure it works properly, start by using echo instead of sshpass … -p 4111 and fine-tune the escaping until the output is exactly what you want the Mikrotik to get.
Actually it’s better to put everything into single quotes. In bash both types of quotes mean “treat this as single argument”, the big difference is that bash tries to substitute plenty of things within double-quoted text while it will pass verbatim whatever single-quoted.
Ok, look, i have my dhcp lease on several computers.
I want to get Ip address of hostname PC.
SO i wrote a bash script that connect via ssh to mikrotik and run a terminal command.
Problem is that I dont know how to get IP address of dhcp lease address with hostname=PC.
I don’t know how to create an empty file, but you can create a non-empty file using e.g. /ip address print file=myfile and then replace its contents: :file set myfile.txt contents=[ip dhcp-server lease get [find host-name=my-HP] address]
But I’m not sure why would you want to save a single value into a file and then download that file using ftp, as if you put it in the command line sent using ssh, the ssh returns that output it to the linux machine:
thanks for reply.
Problem lies somewhere alse abvious.
When sshpass this command
ip dhcp-server lease print file=$n
my script execute without problem.
I use that variable n in later lines of code.
But i dont need all dhcp lease, only with PC hostname, we solve that, but what is difference with that code and this
:global n [ip dhcp-server lease get [find host-name=PC] address];/file print file=$n
set the value of a global-scoped variable named n to the ip address leased to device with hostname PC
print the list of existing files into a file whose name is retrieved from the global variable n
So you end up with a file named ip.add.re.ss.txt. which contains a list of all files currently available on the machine. On my machine it gives no errors if entered directly, so if it causes trouble via ssh, you either haven’t used single quotes as Metod has recommended or there is some other error.
/file print is equivalent to ls / in linux; /file print file=something is equivalent to ls / > something