#!/bin/bash
IP=`mysql -h127.0.0.1 -u root -psomepass billing -e "SELECT ip from users where state = 'on' "`
for i in ${IP[*]} ; do
echo $i
ssh -l admin -i /root/.ssh/id_dsa 15.13.130.194 "/ip firewall address-list add address=$i list=access"
done
can you help me?
because in bash, script work very very slowly
I don’t know about the Perl API, but you could improve performance of that bash script if you don’t spawn a new ssh session for every single command but instead collect commands into a file piped into one ssh session.
#!/bin/bash
TEMPFILE="/tmp/$(basename $0).$$.tmp"
IP=`mysql -h127.0.0.1 -u root -psomepass billing -e "SELECT ip from users where state = 'on' "`
for i in ${IP[*]} ; do
echo "/ip firewall address-list add address=$i list=access" >> $TEMPFILE
done
ssh -l admin -i /root/.ssh/id_dsa 15.13.130.194 < $TEMPFILE
rm $TEMPFILE
Yes, that’s normal. You’re redirecting stdin for the ssh session to take input from a file instead of a terminal, so it informs you that it’s not going to allocate a pseudo terminal for the session because it would be pointless to do so. It’ll still execute all the commands in the file.