Note: The Listed platform will permanently shut down December 31, 2026. Your data published on Listed will still be available in your personal Standard Notes account. Learn more

自動化神器 nushell ,系統檢查範例

原本想說把 nushell 範例都寫在一起,不過這樣會拖稿太久。所以決定隨意一點,想到什麼就發表什麼

nushell 提供方便的程式語言與簡單的和外部互動方式,讓你可以很容易的的檢查系統狀態是否是你預期的

下面範例會幫我找出所有 gpu_開頭沒有正常運作的程序(正常運作定義成strace 結果沒有 futex 文字)

ps|where name =~ "gpu_"|par-each -t 8 {|it| {name: $it.name, out: (do {sudo timeout 5s strace -p $it.pid} | complete |get stderr)}}|filter {|it| $it.out | str contains futex}|get name

範例使用 par-each ,所以他會平行運算,不會每個 process 都需要等五秒鐘

下面範例示範找出所有任務沒有出現在 modulea 的 log 與 moduleb 的 log


let tasks = (ls -s /tasks/ |get name )
let logs = (timeout 60s kubectl logs deployment/ros2-streaming --since=0 -f|lines)
let module_a_log = ($logs | filter {|line| ($line | str contains "module-a") and ($line | str contains "process(): task id") })
let module_b_log = ($logs | filter {|line| ($line | str contains "module_b")})
let task_no_module_a = ($tasks | filter {|it|
  $module_a_log | filter {|line| $line | str contains $it } | is-empty
})
let task_no_module_b = ($tasks | filter {|it|
  $module_b_log| filter {|line| $line | str contains $it } | is-empty
})

You'll only receive email when they publish something new.

More from kjelly
All posts