1. 程式人生 > >判斷web服務

判斷web服務

題目要求

寫一個指令碼判斷你的Linux伺服器裡是否開啟web服務?(監聽80埠)如果開啟了,請判斷出跑的是什麼服務 ,是httpd呢還是nginx又或者是其他的什麼?

參考答案

#!/bin/bash
n=`netstat -lntp |grep ':80 '|wc -l`
if [ $n -eq 0 ]
then
    echo "It not listen port 80"
else
    ser=`netstat -lntp |grep ':80 '|awk -F '/' '{print $NF}'|sed 's/ //g'`
    echo "It is listenning port 80, and the service is $ser