I want to pass variable server inside python command and read the python command result portStatus variable out from command.
for server in `echo $dnsServers | awk -F";" '{print $1" "$2" "$3" "$4" "$5" "$6}'`
do
python3 -c 'import socket;
a_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM);
host=("$server", 53);
portStatus=a_socket.connect_ex(host);'
done
echo $portStatus
Getting this error :
Traceback (most recent call last):
File "<string>", line 1, in <module>
socket.gaierror: [Errno -2] Name or service not known
Traceback (most recent call last):
File "<string>", line 1, in <module>
socket.gaierror: [Errno -2] Name or service not known
Traceback (most recent call last):