从mysql中查询出的结果为:
mysql -Ne "SELECT ip,port FROM op.host WHERE os=‘linux‘ and type=‘支持‘" +------------+------+ | 10.3.1.155 | 22 | | 10.3.1.156 | 22 | | 10.3.1.174 | 22 | | 10.3.1.212 | 2222 | +------------+------+
循环获取IP和PORT
#!/bin/bash tmp=`mysql -Ne "SELECT ip,port FROM op.host WHERE os=‘linux‘ and type=‘支持‘"|while read a b;do echo "$a:$b";done` for i in $tmp do ip=`echo $i |cut -d: -f 1` port=`echo $i |cut -d: -f 2` echo "ip:$ip,port:$port" done
结果为:
ip:10.3.1.155,port:22 ip:10.3.1.156,port:22 ip:10.3.1.174,port:22 ip:10.3.1.212,port:2222
原文地址:http://maoxian.blog.51cto.com/4227070/1975300