从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/bashtmp=`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 $tmpdoip=`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:22ip:10.3.1.156,port:22ip:10.3.1.174,port:22ip:10.3.1.212,port:2222