22

I want to see output from my systemctl commands. For example:

systemctl restart systemd-networkd  

would display the output of

systemctl status systemd-networkd. 

I know that I could write a script that always puts the commands sequentially but I am hoping there is something like

systemctl --verbose restart ....

that didn't make it into the man page.

Stephen Boston
  • 971
  • 1
  • 12
  • 23
  • systemctl usually carries stdout output to a log file, for most systems this file is /var/log/syslog . Is that what you mean? – dGRAMOP May 16 '18 at 13:24
  • @dGRAMOP I'm looking for an immediate display of status after issuing the systemctl command. To view the log output I will have to issue another command. I am looking for a switch that will have the effect of #systemctl restart ; systemctl status – Stephen Boston May 16 '18 at 16:33
  • 1
    May I refer you to Lennarts response: [bug report](https://bugs.freedesktop.org/show_bug.cgi?id=43753) – Richard Cross Jan 15 '20 at 16:10
  • @RichardCross Thank you. What am I to take of it. This report is older than my original post. `systemctl` does not offer a `verbose` switch -- or something like it-- which is what I'm looking for. – Stephen Boston Jan 16 '20 at 00:00
  • @StephenBoston I too was looking for a verbose option on systemctl, and was disappointed to find there isnt one. As you originally suggested it would make perfect sense to have a `--verbose` or `-v` option. Without going into the politics, Lennart has a controlling interest in systemd, and given his response in the bug report I linked to; I would suggest there there unfortunately wont ever be a verbose option. – Richard Cross Jan 16 '20 at 10:59
  • @RichardCross Ah commiseration, yes. Oh well. I suppose he wants to keep the code as simple as he can. Okay. Thanks for the link. – Stephen Boston Jan 16 '20 at 13:28

3 Answers3

5

To my knowledge, there is no such thing. That being said, you can go ahead and "make you own":

We're going to edit out bashrc file to add this as a an alias command

echo "startstat(){ systemctl start \$*; systemctl status \$* }" >> ~/.bashrc

Note that this will only work for bash sessions and for the user you're running it for, so don't run this inside stuff that doesn't run bashrc before starting.

You can then start services and immediately get the status by running

startstat [arguments to pass to BOTH systemctl start AND systemctl status]

Sample usage:

startstat systemd-networkd 

If you want to wait a little bit before checking the status, you can always add a sleep between:

Just nano ~/.bashrc, scroll to the bottom (or if you added things, whichever line it's at), and just add sleep [seconds]; between systemctl start \$*; and systemctl status \$*;

If you want the status to be run after the start is finished, you can put a singular & sign with a space in front of it between the \$* and the ; to fork it off into background.

dGRAMOP
  • 753
  • 5
  • 19
  • Thank you very much for this @dGramop . I do have a simple script, but I was wondering if there was a switch. It seems like a natural. – Stephen Boston May 18 '18 at 11:14
1

Unfortunately systemctl does not provide a "verbose" option like most Unix commands do.

One solution is to increase SYSTEMD_LOG_LEVEL to debug (info is useless here) and then filter the output like e.g.:

$ SERVICES="smartmontools cron xxxxx"
$ SYSTEMD_LOG_LEVEL=debug systemctl restart $SERVICES 2>&1|egrep "Got result|Failed"
Failed to restart xxxxx.service: Unit xxxxx.service not found.
Got result done/Success for job cron.service
Got result done/Success for job smartmontools.service

You can also add a prefix like e.g.

$ SYSTEMD_LOG_LEVEL=debug systemctl restart $SERVICES 2>&1|egrep -i "Got result|Failed"|sed 's,^,restart: ,'
restart: Failed to restart xxxxx.service: Unit xxxxx.service not found.
restart: Got result done/Success for job cron.service
restart: Got result done/Success for job smartmontools.service

SYSTEMD_LOG_LEVEL might not be available on all systems.

reichhart
  • 813
  • 7
  • 13
1

systemctl does not have a verbose option. If you want to see the output of the service you are running in real time, what you can do is to open another terminal and run:

sudo journalctl --unit=systemd-networkd.service -f

Journalctl documentation: https://www.freedesktop.org/software/systemd/man/journalctl.html

marcosdsanchez
  • 2,529
  • 2
  • 17
  • 20