F
F
fokin_nikolay19892017-05-18 08:50:02
bash
fokin_nikolay1989, 2017-05-18 08:50:02

How to substitute each line into the execution of a command from a BASH file?

I want to connect to each computer on the network and execute the same command (pdsh is not suitable), so I decided to write a script

#!/bin/bash
FILE=$1
while read LINE; do
sshpass -p 123456 ssh -o UserKnownHostsFile-/dev/null -o StrictHostKeyChecking=no [email protected]$LINE 'date'
done < $FILE

I execute ./inst ip
It substitutes the ip value only from the first line, but how can I make it substitute all subsequent ones in turn?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Komarov, 2017-05-18
@fokin_nikolay1989

for fl in `cat $1`; do
    sshpass -p 123456 ssh -o UserKnownHostsFile-/dev/null -o StrictHostKeyChecking=no [email protected]$fl 'date'
done

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question