Score:0

How to check several (n) last statuses of a systemd service?

bd flag

I asked google and ChatGPT about that, i.e. see a specified n recent status of a service, obviously in chronological order.

ChatGPT told me this would work:

systemctl  status --quiet example.service -n 5

But this does NOT work, at least for me.

Score:1
in flag

The manual page man systemctl explains why that doesn't work for you:

-n, --lines=

When used with status, controls the number of journal lines to show, counting from the most recent ones. Takes a positive integer argument, or 0 to disable journal output. Defaults to 10.

So systemctl status example.service -n 5 shows LESS rather than more/all information.

systemctl status

... Note that this operation only displays runtime status, i.e. information about the current invocation of the unit (if it is running) or the most recent invocation (if it is not running anymore, and has not been released from memory).

But in the same paragraph it does instruct you what to do instead to get information about previous invocations:

Information about earlier invocations, invocations from previous system boots, or prior invocations that have already been released from memory may be retrieved via journalctl --unit=.

Note that for many of my services I'll see a warning "Journal has been rotated":

systemctl status httpd

● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2023-08-11 15:31:26 CEST; 6 days ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 21095 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS)
 Main PID: 888 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─  888 /usr/sbin/httpd -DFOREGROUND
           └─30179 /usr/sbin/httpd -DFOREGROUND

Warning: Journal has been rotated since unit was started. 
Log output is incomplete or unavailable.
^^^^^^^^^     ^^^^^^^^^     ^^^^^^^^^     ^^^^^^^^^

Where that last line is crucial and explains that the recommended action of running journalctl --unit= shows nothing particularly useful for me:

journalctl --unit=httpd.service

-- No entries --

Your mileage may vary for that.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.