- 追加された行はこの色です。
- 削除された行はこの色です。
目次~
#contents
*概要 [#m0de1b54]
Webページ上にホスト名、時刻、プロセスリストを出力するPython CGIのサンプル
*サンプル [#c15cd032]
**index.py [#t623780e]
#!usr/bin/python3
#
# index page create
#
## data import os, datetime, subprocess
sysname = os.uname()[1]
date = datetime.datetime.now()
now = '{0:%Y/%m/%d %H:%M:%S}'.format(date)
cmd = "ps ax | grep -v '\[' | sed 's/$/<br>/g' | grep -v 'sed'"
procs = subprocess.check_output(cmd, shell=True).decode('utf-8')
## HTML
html = """
<HTML>
<HEAD>
<title>index page</title>
</HEAD>
<BODY>
<div align="center">
<hr>
%s
<hr>
<table>
<tr><td>Date : </td><td>%s</td></tr>
<tr><td>Procs : </td><td>%s</td></tr>
</table>
</div>
</BODY>
</HTML>
"""
## output
print ( 'Content-type: text/html' )
print ( '' )
print ( html % (sysname,now,procs) )
# EOF