簡易なサーバの状態表示

簡易なサーバの状態表示

Linux(FreeBSD)簡易なサーバの状態表示

Linux サーバのあらゆる情報を html で見たいと思って、強引な即席スクリプトを作ってみました。滅多に使わないコマンドは忘れちゃうので備忘録程度に・・・。もちろん、商用サービスとかだとローカルやリモートからのリアルタイム監視が必要でしょうけどね。

#!/bin/bash

HTML_FILE="server.html"

echo "<html><head><title>SERVER INFO</title></head><body>" > ${HTML_FILE}

# date
echo "<pre>" >> ${HTML_FILE}
echo "[Date]" >> ${HTML_FILE}
date "+%Y-%m-%d %H:%M:%S" >> ${HTML_FILE}
echo "</pre>" >> ${HTML_FILE}

# OS
echo "<pre>" >> ${HTML_FILE}
echo "[OS]" >> ${HTML_FILE}
cat /etc/issue | grep '^.' | awk '{print $3" "$4}' >> ${HTML_FILE}
echo "</pre>" >> ${HTML_FILE}

# kernel
echo "<pre>" >> ${HTML_FILE}
echo "[Kernel]" >> ${HTML_FILE}
uname -a | head -n 1 | awk '{print $1" "$2" "$3}' >> ${HTML_FILE}
echo "</pre>" >> ${HTML_FILE}

# login user
echo "<pre>" >> ${HTML_FILE}
echo "[Login User]" >> ${HTML_FILE}
who >> ${HTML_FILE}
echo "</pre>" >> ${HTML_FILE}

# df
echo "<pre>" >> ${HTML_FILE}
echo "[Disk Info]" >> ${HTML_FILE}
df -h >> ${HTML_FILE}
echo "</pre>" >> ${HTML_FILE}

# load average
echo "<pre>" >> ${HTML_FILE}
echo "[Load Average]" >> ${HTML_FILE}
uptime | sed -e 's/^\s.//g' >> ${HTML_FILE}
echo "</pre>" >> ${HTML_FILE}

# netstat
echo "<pre>" >> ${HTML_FILE}
echo "[TCP Listen]" >> ${HTML_FILE}
netstat -an | grep -E 'Proto Recv-Q|tcp' | sed -e 's/</\&lt;/g' | sed -e 's/>/\&gt;/g' >> ${HTML_FILE}
echo "</pre>" >> ${HTML_FILE}

# ps
echo "<pre>" >> ${HTML_FILE}
echo "[Prosess]" >> ${HTML_FILE}
ps auxw | sed -e 's/</\&lt;/g' | sed -e 's/>/\&gt;/g' >> ${HTML_FILE}
echo "</pre>" >> ${HTML_FILE}

echo "</body></html>" >> ${HTML_FILE}

exit 0;

最終更新日:

関連記事

人気記事

新着情報