Bash script telnet conexión + bucle for

I am trying to make bash script that connects via telnet and executes multiple commands using for loop.

Esto es lo que he probado:

{echo "username"; sleep 1; echo "password";  for host in {`cat hosts`}; do echo "show configuration | display set | match $host";done; sleep 15; } | telnet <ip>

preguntado el 12 de febrero de 14 a las 07:02

You might want to look into ssh. That will let you connect to the remote host securely without your password being on the commandline. -

¿Cuál es tu pregunta real aquí? -

My question is what i am doing wrong cause it does not execute , the commands properly , for example the first host which is trying to loog for looks like this {} and it should be withouth the brackets. -

1 Respuestas

The additional brackets are because of

for host in {`cat hosts`} ; do

you don't need them

for host in `cat hosts` ; do


for host in $(hosts) ; do

But as stated in the comments take a look at SSH (sending the credentials in clear text and storing them in a script is not the best idea)

for host in $(cat hosts) ; do
    ssh user@$host "show configuration | display set | match $host"

Respondido 12 Feb 14, 09:02

Ok i've tried with ssh but stil didnt work : #!/bin/bash ssh user@ <<'ENDSSH' for hosts in {cat hosts};do "show configuration | display set | match $hosts" ; done ENDSSH - user2642601

@user2642601 Why the brackets? Which shell are you using? - Mateo

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.