brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: systemctl show --value prints one clean systemd property for scripts

Systemd
~/tips/tip-systemd-show-value-for-scripts

systemctl show nginx.service -p MainPID --value

Prints a single unit property without labels, so scripts can read it directly.

Parsing the output of systemctl status is fragile, and show already gives machine-readable fields.

systemctl show nginx.service -p MainPID --value
systemctl show nginx.service -p ActiveEnterTimestamp --value

-p selects a property and --value prints only its value without the Name= prefix, so it drops straight into a variable: pid=$(systemctl show nginx -p MainPID --value). Without -p, the command prints every property, which is useful to search with grep. A stopped service reports MainPID=0. The same works for --user units. Run systemctl show nginx once to see which property names exist, then pick the ones you need.

Further reading: systemctl manual page

More Systemd tips [Service] sudo mkdir -p /etc/systemd/system/service.d [Service] printf 'hunter2' | sudo systemd-creds encrypt --name=dbpass – dbpass.cred systemd-analyze timespan 1h30min All Systemd tips (88) All topics

Link