Answer the question
In order to leave comments, you need to log in
How to write a loop for reading data from a file, splitting the data into variables and making a connection?
There is a file with content
37.33.61.72;root;123456
46.55.118.33;root;root
62.21.72.67;root;12345
87.25.74.122;root;root
89.28.30.43;root;root
sshpass -p $pass ssh [email protected]$host
Answer the question
In order to leave comments, you need to log in
For example, how you can get the desired command from each line of the list:
#!/bin/bash
while read -r LINE;
do
awk -F';' '{print "sshpass -p "$3" ssh " $2"@"$1}'
done < ${1}
sshpass -p 12345 ssh [email protected]
sshpass -p root ssh [email protected]
sshpass -p root ssh [email protected]
If I understand correctly, it will look something like this:
where x.log is your file from which the data is read
> "and if everything is fine output Ok"
where to output?) if successful, you will log in to the remote machine and you will have another console in front of you.
> "and issue depending on this OK or BAD"
on failure, you will be given something like this:
agree that this is a little more informative than just BAD, at least it’s clear which address has failed, and it’s probably more correct to throw the error output into the log file so that you can then analyze if anything
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question