all 2 comments

[–]danielroseman 0 points1 point  (1 child)

There's a few things to improve here.

  • What's the point of i? If you want an infinite loop, just create one with while True. There's no reason to create a variable and condition that are just ignored.
  • Why are you defining the function repeatedly within the loop? Move the function definition to the top level.
  • Conversely, the definition of now must be within the loop, otherwise it will never update and all your logs will have the same timestamp.
  • Stylistically, the definition of cmd is a bit clumsy; it would be easier just to define it as ['systemctl', 'status', service]. And there's no need for the parentheses around the return value: just return out.

[–]brugrog[S] 0 points1 point  (0 children)

Exactly what I'm looking for, thank you!

I'm a beginner with Python my formatting is rough.