# value equal if [ ${ans_lines} -eq ${lines} ] then echo "lines is ok" else echo "lines is not ok" fi # file exist hdfs dfs -test -d ${HDFS_path}/wap if [ $? == 0 ]; then hdfs dfs -rmr ${HDFS_path}/wap fi
for loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
for i in {1..10}; do echo $i; done echo "**************" END=10 for i in $(seq 1 $END); do echo $i; done echo "**************" INTERVAL=2 for i in $(seq 1 $INTERVAL $END); do echo $i; done
for i in {2..5}; do tablesuffix=$i echo $tablesuffix sleep 1; done
tmp = set() lines = output.split('\n') for line in lines: if str(line).startswith('tcp'): items = str(line).split() if not items[3].startswith('127.0.0.1') : if items[3].startswith('0.0.0.0') or items[3].startswith(':::') or items[3].split(':')[0] != items[4].split(':')[0]: print('%s\t\t%s\t\t%s' %(items[3], items[4], items[6])) tmp.add(int(items[3].split(':')[-1]))
listeningPort=list(tmp) listeningPort.sort() listeningPort # listeningPort.sort() for p in listeningPort: print(p) ######### inUsePortInfo = {} retCode,output = commands.getstatusoutput('netstat -ntp -4 |grep ESTABLISHED') lines = output.split('\n') for line in lines: if str(line).startswith('tcp'): items = str(line).split() if items[3].split(':')[0] != items[4].split(':')[0]: port = items[3].split(':')[1] + ' ' + items[6] # print(line) tmp = inUsePortInfo.get(port, list()) tmp.append(items[4]) tmp.sort() inUsePortInfo[port] = tmp # for k,v in inUsePortInfo.items(): # print('%s \t %s' %(k, v))
for i in sorted(inUsePortInfo): print('%s \t %s' %(i, inUsePortInfo[i]))
listeningPort.sort() listeningPort
Expected Output: port, foreign address list
Filter local server 127.0.0.1 local 和 remoter 都是本机