Commit f4d1578b authored by jinkaiqiang's avatar jinkaiqiang

feature:获取所有容器内部的日志文件

parent 0813d8ea
# -*- coding:utf-8 -*-
'''
获取所有docker容器内的版本文件
'''
import os
if __name__ == '__main__':
# 获取所有启动的容器
with os.popen("docker ps | awk '{print $1,$2}'") as f:
docker_containers = f.read()
# 根据启动的容器,依次获取内部的version.txt,版本文件
container_list = docker_containers.split("\n")
verison_info = ""
for container_str in container_list:
if (container_str == "CONTAINER ID" or not container_str):
continue
container = container_str.split(" ")
c_id = container[0]
c_image = container[1]
get_version_cmd = f"docker exec -it {c_id} cat version.txt"
with os.popen(get_version_cmd) as f:
print(f"正在获取镜像{c_image}版本")
get_version_result = f.read()
# 记录
verison_info += f"镜像:{c_id}-{c_image},获取版本结果为:\n{get_version_result}\n"
# 写入文件
with open("get_all_container_version.txt", 'w') as f:
f.write(verison_info)
# -*- coding:utf-8 -*-
if __name__ == '__main__':
table_value_str = '''1401734842471800834 1401723910119043074 20210607105644079 2 5 2021-06-07T11:26:44+08:00 2021-06-07 10:56:44.673 NULL
1401734891385774082 1401723910119043074 20210607105655753 2 1 2021-06-07T11:26:55+08:00 [gmt_create2021-06-07 10:57:04][charsetUTF-8][gmt_payment2021-06-07 10:57:10][notify_time2021-06-07 10:57:10][subject测试-IOT设备运维平台V1.0-企业版][buyer_id2088902407659583][invoice_amount0.01][version1.0][notify_id2021060700222105710059581411695231][fund_bill_list[{"amount":"0.01","fundChannel":"ALIPAYACCOUNT"}]][notify_typetrade_status_sync][out_trade_no20210607105655753][total_amount0.01][trade_statusTRADE_SUCCESS][trade_no2021060722001459581404964773][auth_app_id2021002147611434][receipt_amount0.01][point_amount0.00][buyer_pay_amount0.01][app_id2021002147611434][seller_id2088921658176829] 2021-06-07 10:56:56.347 2021-06-07 10:57:10.677'''
for item in table_value_str.split('\n'):
table_value_list = item.split("\t")
print(",".join([f"'{item}'" if item != 'NULL' else 'NULL' for item in table_value_list]))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment