vasilisc@vasilisc:~/bin$ cat pingself.sh
#!/bin/bash
export ping_ip=`/sbin/ifconfig eth0 | awk '/inet addr:/ { print $2 }' | awk '{ split($0,ip,":") } END { print ip[2] }'`;
echo $ping_ip
ping -c 4 $ping_ip
exit 0
vasilisc@vasilisc:~/bin$ ./pingself.sh
172.16.1.2
PING 172.16.1.2 (172.16.1.2) 56(84) bytes of data.
64 bytes from 172.16.1.2: icmp_seq=1 ttl=64 time=0.040 ms
64 bytes from 172.16.1.2: icmp_seq=2 ttl=64 time=0.038 ms
64 bytes from 172.16.1.2: icmp_seq=3 ttl=64 time=0.039 ms
64 bytes from 172.16.1.2: icmp_seq=4 ttl=64 time=0.040 ms
--- 172.16.1.2 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2997ms
rtt min/avg/max/mdev = 0.038/0.039/0.040/0.004 ms
vasilisc@vasilisc:~/bin$