ホスト名とプロセスリストが記述されたHTMLを生成するCGI
http://extstrg.asabiya.net/pukiwiki/index.php?%A5%DB%A5%B9%A5%C8%CC%BE%A4%C8%A5%D7%A5%ED%A5%BB%A5%B9%A5%EA%A5%B9%A5%C8%A4%AC%B5%AD%BD%D2%A4%B5%A4%EC%A4%BFHTML%A4%F2%C0%B8%C0%AE%A4%B9%A4%EBCGI目次
概要 †
Webページ上にホスト名、時刻、プロセスリストを出力するPython CGIのサンプル
サンプル †
転送用HTML †
転送元ディレクトリに格納する。(/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>
スクリプト †
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
Last-modified: 2019-01-03 (木) 23:35:49 (2119d)