HELP : GET IPV4 and IPV6 from remote Servers
by steph007 from LinuxQuestions.org on (#590YQ)
Hello ,
I created a script which allows to have the ipv4 and ipv6 address of several remote servers, except that the commands I use work on some servers and not on others, knowing that the servers are the same OS version.
The commands are as follows :
1)command to connect to the remote server with the exuction of the command to have the IPV4
ssh -o "StrictHostKeyChecking no" myuser@$SERVER -p 22 'sudo ip -4 addr | grep inet | sed '1d' ' 1> ipv4_address.txt 2> err_ipv4.txt
2) command to connect to the remote server with the exuction of the command to have the IPV6
ssh -o "StrictHostKeyChecking no" myuser@$SERVER -p 22 'sudo ip -6 addr | grep inet6 | sed '1d' ' 1> ipv6_address.txt 2> err_ipv6.txt
3) store information on variables
ipv4=`cat ipv4_address.txt | awk '{print $2}' `
ipv6=`cat ipv6_address.txt | awk '{print $2}' `
the result is :
server1Red Hat Enterprise Linux Server release 6 xx.xx.xx.xx /xxxxxx::xxx:xxxx:xxxx:xxxxx/64
server2 Red Hat Enterprise Linux Server release 6 xx.xx.xx.xx /xxxxxx::xxx:xxxx:xxxx:xxxxx/64
I would like to know why I get the result I want just for some servers and not for the all servers
Thank you.


I created a script which allows to have the ipv4 and ipv6 address of several remote servers, except that the commands I use work on some servers and not on others, knowing that the servers are the same OS version.
The commands are as follows :
1)command to connect to the remote server with the exuction of the command to have the IPV4
ssh -o "StrictHostKeyChecking no" myuser@$SERVER -p 22 'sudo ip -4 addr | grep inet | sed '1d' ' 1> ipv4_address.txt 2> err_ipv4.txt
2) command to connect to the remote server with the exuction of the command to have the IPV6
ssh -o "StrictHostKeyChecking no" myuser@$SERVER -p 22 'sudo ip -6 addr | grep inet6 | sed '1d' ' 1> ipv6_address.txt 2> err_ipv6.txt
3) store information on variables
ipv4=`cat ipv4_address.txt | awk '{print $2}' `
ipv6=`cat ipv6_address.txt | awk '{print $2}' `
the result is :
server1Red Hat Enterprise Linux Server release 6 xx.xx.xx.xx /xxxxxx::xxx:xxxx:xxxx:xxxxx/64
server2 Red Hat Enterprise Linux Server release 6 xx.xx.xx.xx /xxxxxx::xxx:xxxx:xxxx:xxxxx/64
I would like to know why I get the result I want just for some servers and not for the all servers
Thank you.