您可以使用flask
:
创建脚本flexlm.py
# pip install flask
from flask import Flask, Response
import subprocess
app = Flask(__name__)
@app.route("/status")
def status():
run = subprocess.run(['/opt/flexlm/lmutil', 'lmstat', '-a'], capture_output=True)
return Response(run.stdout, mimetype='text/plain')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080)
注意:必须自定义参数subprocess.run
运行flask
应用服务器:
[...]$ python3 flexlm.py
* Serving Flask app 'flexlm' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on all addresses.
WARNING: This is a development server. Do not use it in a production deployment.
* Running on http://10.202.120.7:8080/ (Press CTRL+C to quit)
10.202.241.181 - - [01/Mar/2022 14:38:04] "GET / HTTP/1.1" 404 -
10.202.241.181 - - [01/Mar/2022 14:38:08] "GET /status HTTP/1.1" 200 -
转到 http://xyz:5000/status