Community discussions

MikroTik App
 
tomislav91
Member
Member
Topic Author
Posts: 303
Joined: Fri May 26, 2017 12:47 pm

dhcp lease - sshpass script dont work

Wed Feb 08, 2023 9:34 am

#!/bin/bash
user=admin
read -sp 'Password ' pass
log=StrictHostKeyChecking=no
locdir=/home/user/backup/
rm -rf /root/.ssh/known_hosts
d=$(date '+%d-%b-%Y')
mkdir $locdir/user_$d
cd $locdir/user_$d
while read n h;do
sshpass -p $pass ssh -o $log -n $user@$h -p 4777 '/ip dhcp-server lease;:foreach i in=[find where host-name="pc"] do={:put [get $i address]}' file=$n
sshpass -p $pass ssh -o $log -n $user@$h -p 4777 file remove $n.txt
done < $locdir/hostscg.txt
This is my script which i use to download dhcp lease and grep some IPs with some hostname. I did it earlier like this: get all dhcp lease and with awk/sed/grep get IP addresses.
I want now to use it with mikrotik script to grep it, and this command
/ip dhcp-server lease;:foreach i in=[find where host-name="pc"] do={:put [get $i address]}
works on terminal, but not here.
Why?
Password Warning: Permanently added '[10.10.46.1]:22' (RSA) to the list of known hosts.
expected end of command (line 1 column 100)
Connected to 10.10.46.1.
File "/RemoteShop1.txt" not found.
no such item

Who is online

Users browsing this forum: No registered users and 17 guests