I need to read the following command outputs into an array, and then loop through that array within another command.
- File hosts contains 2 IP addresses:
- 192.168.3.78
- 192.168.3.79
should read the output of sed ":a;N;$!ba;s/\n/ /g" $hosts into array sednames
sednames=( $(sed ":a;N;$!ba;s/\n/ /g" $hosts) )
I then have another loop to read through static ports (does work, as the ports are defined in the script). I want to then run each IP through this command with each port
m is supposed to be the array of IP's i is the list of ports (which does work)
for m in "$sednames"
do
echo "m = $m"
var=$(python -c "import socket; print(socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect_ex((\"$m\", $i)))")
The problem I am running into is that sednames and m only seems to contain the first ip, nothing more. Also, the python script barfs on the newline after .78, so that's the reasoning for the sed command to eliminate newlines to loop through each string in the array.