如果您正在使用類似Debian 的發行版並且是新用戶或剛開始作為系統管理員 的職業生涯,您可能已經知道更新軟體包的重要性使用apt 更新。您可能還想了解每個軟體包的用途,以了解有關 Linux 的更多資訊。此外,系統管理員 (sysadmin) 經常需要與利害關係人溝通或記錄哪些更新是緊急的或與安全相關的。
在這篇文章中,我將向您展示如何結合 Python、apt list -u 命令和 Gemini AI 來建立人類可讀的待處理軟體包更新摘要。
目標?
- 使用 apt list -u 指令檢索 Debian 上待處理更新的清單。 注意: 如果需要,您可以使用以下命令修改輸出:
apt list -u | awk '{ print }' | sed 's|/.*||'
- 將此清單傳送給 Gemini AI(使用 Google 的生成庫)。
- 使用AI對每個包裝更新的重要性進行分類和總結。
- 將結果儲存為 Markdown 檔案以便於分享。
要求 ?
- Python 3.8
- Google Gemini API 金鑰
- 所需函式庫:pip install google-generativeai 環境
- 基於 Debian 的系統:此腳本依賴 apt 指令。
守則
以下是兩個腳本的解決方案的細分:
apt_list.py
此腳本執行 apt list -u 以取得掛起的更新,處理輸出,並使用提示功能從 Gemini AI 取得分類摘要。
import subprocess from utils.gemini_cfg import prompt try: # Run 'apt list -u' to list upgradable packages result = subprocess.run(["apt", "list", "-u"], capture_output=True, text=True, check=True) output = result.stdout # Get command output # Use the Gemini AI model to summarize the updates summary = prompt(output) # Save the AI-generated summary to a Markdown file with open("./gemini_result.md", "w") as file: file.write(summary) print("Summary saved to gemini_result.md") except subprocess.CalledProcessError as e: print("Error while running apt list:", e)
gemini_cfg.py
此腳本配置 Gemini API 並定義 AI 生成內容的提示功能。
import google.generativeai as genai from environs import Env # Load API key from .env file env = Env() env.read_env() key = env("TOKEN") # Replace with your environment variable key name # Configure Gemini API genai.configure(api_key=key) model = genai.GenerativeModel("gemini-1.5-flash") # Function to prompt Gemini AI for summaries def prompt(content): message = ( "You work as a sysadmin (Debian server infrastructure). " "You must create a list categorizing the importance in terms of security and priority, " "providing a brief summary for each package so that business managers can understand " "what each library is from this output of the `apt list -u` command: " f"{content}" ) response = model.generate_content([message]) return response.text
- 執行 apt_list.py 腳本:python apt_list.py
-
此腳本執行以下操作:
- 檢索待處理的 Debian 軟體包更新。
- 將清單傳遞給 Gemini AI 進行分類和解釋。
- 將 AI 產生的輸出儲存到 gemini_result.md。
開啟gemini_result.md 可查看清晰、分類的更新摘要,以便於溝通。
範例輸出
以下是產生的摘要的範例:
## Debian Package Update List: Priority and Security The list below categorizes the packages available for update, considering their importance in terms of security and business operation priority. The classification is subjective and may vary depending on your company's specific context. **Category 1: High Priority - Critical Security (update immediately)** - **linux-generic, linux-headers-generic:** Critical kernel updates to fix security vulnerabilities. - **libcurl4:** Resolves potential security issues for data transfer operations. ... **Category 2: High Priority - Maintenance and Stability (update soon)** * **`e2fsprogs`, `logsave`:** Packages related to ext2/ext3/ext4 file systems. Update to ensure data integrity and file system stability. **Medium-High priority.** ... **Category 3: Medium Priority - Applications (update as needed)** * **`code`:** Visual Studio Code editor. Update for new features and bug fixes, but not critical for system security. * **`firefox`, `firefox-locale-en`, `firefox-locale-pt`:** Firefox browser. Updates for security fixes and new functionalities. Priority depends on Firefox usage in your infrastructure. ...
結論
借助一點 Python 和 Gemini AI,您可以自動化並改進 Debian 軟體包更新的溝通方式。該腳本是將 AI 整合到系統管理工作流程中的良好基礎。這篇文章出於教育目的,因此請注意 Gemini API 資源以及系統的安全處理。
感謝您的閱讀! ?
以上是使用 Python 和 Gemini (gemini--flash) 自動產生 Debian 軟體包更新摘要的詳細內容。更多資訊請關注PHP中文網其他相關文章!

每天學習Python兩個小時是否足夠?這取決於你的目標和學習方法。 1)制定清晰的學習計劃,2)選擇合適的學習資源和方法,3)動手實踐和復習鞏固,可以在這段時間內逐步掌握Python的基本知識和高級功能。

Python在Web開發中的關鍵應用包括使用Django和Flask框架、API開發、數據分析與可視化、機器學習與AI、以及性能優化。 1.Django和Flask框架:Django適合快速開發複雜應用,Flask適用於小型或高度自定義項目。 2.API開發:使用Flask或DjangoRESTFramework構建RESTfulAPI。 3.數據分析與可視化:利用Python處理數據並通過Web界面展示。 4.機器學習與AI:Python用於構建智能Web應用。 5.性能優化:通過異步編程、緩存和代碼優

Python在開發效率上優於C ,但C 在執行性能上更高。 1.Python的簡潔語法和豐富庫提高開發效率。 2.C 的編譯型特性和硬件控制提升執行性能。選擇時需根據項目需求權衡開發速度與執行效率。

Python在現實世界中的應用包括數據分析、Web開發、人工智能和自動化。 1)在數據分析中,Python使用Pandas和Matplotlib處理和可視化數據。 2)Web開發中,Django和Flask框架簡化了Web應用的創建。 3)人工智能領域,TensorFlow和PyTorch用於構建和訓練模型。 4)自動化方面,Python腳本可用於復製文件等任務。

Python在數據科學、Web開發和自動化腳本領域廣泛應用。 1)在數據科學中,Python通過NumPy、Pandas等庫簡化數據處理和分析。 2)在Web開發中,Django和Flask框架使開發者能快速構建應用。 3)在自動化腳本中,Python的簡潔性和標準庫使其成為理想選擇。

Python的靈活性體現在多範式支持和動態類型系統,易用性則源於語法簡潔和豐富的標準庫。 1.靈活性:支持面向對象、函數式和過程式編程,動態類型系統提高開發效率。 2.易用性:語法接近自然語言,標準庫涵蓋廣泛功能,簡化開發過程。

Python因其簡潔與強大而備受青睞,適用於從初學者到高級開發者的各種需求。其多功能性體現在:1)易學易用,語法簡單;2)豐富的庫和框架,如NumPy、Pandas等;3)跨平台支持,可在多種操作系統上運行;4)適合腳本和自動化任務,提升工作效率。

可以,在每天花費兩個小時的時間內學會Python。 1.制定合理的學習計劃,2.選擇合適的學習資源,3.通過實踐鞏固所學知識,這些步驟能幫助你在短時間內掌握Python。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

Dreamweaver CS6
視覺化網頁開發工具

WebStorm Mac版
好用的JavaScript開發工具

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

記事本++7.3.1
好用且免費的程式碼編輯器