I have a script in which I am reading from a csv file where it contains SourceIp, DestinationIP,Source Ports, Destination Ports.
First I am reading the sourceIp and trying to do ssh over it (I am able to do it successfully), here I am trying to get a pseudo terminal and want to execute a for loop that will iterate over the sourcePorts(hyphen separated) and destinationPorts.
Input File Content :
10.X.X.9,10.X.X.23,8140-61613,1521-1524-1525-1526-1530-1531-8140-61613
Script :
export lastSourceIP=""
export lastDestinationIP=""
export fqdn=""
export sourceFqdn=""
x=0
export username="sjain";
export location="/home/sjain/poc";
export baseLocation="10.X.X.9"
while IFS="," read f1 f2 f3 f4
do
x=$(($x+1))
TMP=$(mktemp)
TMP2=$(mktemp)
echo "Source IP : $f1"
echo "Destination IP : $f2"
echo "Source Ports : $f3"
echo "Destination Ports : $f4"
export sourceIP=$f1
export destIP=$(echo "$f2" | tr -d '\n')
export port=$(echo "$f3" | tr -d '\n')
export destinationPorts=$(echo "$f4" | tr -d '\n')
ssh -t -t $username@$sourceIP 'bash -s' <<ENDSSH
(IFS='-'; for sourceP in $port; do
(for destinationP in $destinationPorts; do
echo "$sourceP" - "$destinationP"
done;)
done;)
exit
ENDSSH
done < ipaddress.csv
But when I am executing this script , it is not printing sourceIP - DestinationIp values. Here , is the output that I am getting on console.
Output:
Source IP : 10.X.X.9
Destination IP : 10.X.X.23
Source Ports : 8140-61613
Destination Ports : 1521-1524-1525-1526-1530-1531-8140-61613
tcgetattr: Inappropriate ioctl for device
(IFS='-'; for sourceP in 8140-61613; do
(for destinationP in 1521-1524-1525-1526-1530-1531-8140-61613; do
echo "" - ""
done;)
done;)
exit
[[email protected] ~]$ (IFS='-'; for sourceP in 8140-61613; do
> (for destinationP in 1521-1524-1525-1526-1530-1531-8140-61613; do
> echo "" - ""
> done;)
> done;)
-
[[email protected] ~]$ exit
exit
Connection to 10.X.X.9 closed
.
Expected Output :
8140-1521
8140-1524
.... and so on
Please help where I am doing wrong.