I'm trying to combine two lists in the output of a bash script. One list is a list of machine names. The other list is a list of IP addresses. It then outputs whether or not it can telnet to the IP on port 3389. It's taking an inventory of which windows machines are responding on that port.
Here's what I came up with:
#!/bin/bash
file1="machine_list.txt"
file2="ip_list.txt"
HOSTS=$(cat "$file1")
IP=$(cat "$file2")
for h in $HOSTS
do
for i in $IP
do
echo "checking RDP port on host: $h"
/usr/bin/telnet $i 3389
echo
sleep 2
done
done
The output of a successful connection should look like this:
checking RDP port on host: USAMZADP3000
Trying 10.1.233.65...
Connected to 10.1.233.65.
Escape character is '^]'
But what it's really doing is looping over the same machine name and giving a different IP address for the same machine name. I want the machine name and the IP address to be accurate and have a 1 to 1 correlation.
What am I doing wrong? How can I get the result I want?