• 追加された行はこの色です。
  • 削除された行はこの色です。
目次~
#contents

*概要 [#m0de1b54]
Webページ上にホスト名、時刻、プロセスリストを出力するPython CGIのサンプル

*サンプル [#c15cd032]
**index.py [#t623780e]
**転送用HTML [#x7dac4e9]
転送元ディレクトリに格納する。(/var/www/htmlなど)

-index.html
 <!DOCTYPE html>
 <html lang="ja">
 <head>
 <meta charset="uft-8">
 <script>
 setTimeout("location.href='/cgi-bin/index.py'",0);
 </script>
 <title>redirect</title>
 </head>
 <body>
 </body>
 </html>

**スクリプト [#t68f2587]
CGIの実行権限が付与されたディレクトリに格納する。(/var/www/cgi-binなど)

-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



トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS