1

I use systemd-run --user a lot to run things. I want to be able to list only those transient units, but there seems to be no option to systemctl --user list-units to do it. I also cannot list the Transient propery in systemctl --user list-units --output json, so this is also not working for me.

How do I list only transient jobs (Transient=yes)?

neingeist
  • 111
  • 3

1 Answers1

1

You can always loop over all units and run systemctl --user show -p Transient --value on each.

systemctl --user list-units --full --no-legend --no-pager --all |
  while IFS=' ' read -r u rest; do
    [ "$(systemctl --user show -p Transient --no-pager --value -- "$u")" = yes ] &&
      printf '%s\n' "$u"
  done

A user-unit-prop-grep script could be written as:

#! /bin/sh -
systemctl --user list-units --full --no-legend --no-pager --all |
  while IFS=' ' read -r u rest; do
    systemctl --user show --no-pager -- "$u" |
      grep -H --label="$u" "$@"
  done

And then to list units with Transient=yes:

user-unit-prop-grep -lx Transient=yes

Or print the value of the Transient property alongside each unit name:

user-unit-prop-grep -Po '^Transient=\K.*'

That's quite slow as it runs several commands per unit.

Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501