Как посмотреть вывод сервиса linux

How to see full log from systemctl status service?

I check service status with systemctl status service-name . By default, I see few rows only, so I add -n50 to see more. Sometimes, I want to see full log, from start. It could have 1000s of rows.
Now, I check it with -n10000 but that doesn’t look like neat solution. Is there an option to check full systemd service log similar to less command?

6 Answers 6

Just use the journalctl command, as in:

journalctl -u service-name.service 

Or, to see only log messages for the current boot:

journalctl -u service-name.service -b 

For things named .service , you can actually just use , as in:

But for other sorts of units (sockets, targets, timers, etc), you need to be explicit.

In the above commands, the -u flag is short for —unit , and specifies the name of the unit in which you’re interested. -b is short for —boot , and restricts the output to only the current boot so that you don’t see lots of older messages. See the journalctl man page for more information.

appending -e will start the log at the end removing the need to scroll, but without printing the entire log beforehand.

Actually, this was not helpful for me — I want only the output since the unit was (re)started. sudo systemctl -n 99999 status gives me that, but apparently journalctl can only filter «from boot», not «from service start».

systemctl can include the complete output of its status listing, without truncation., by adding the -l flag:

systemctl -l status service-name 

-l : don’t truncate entries with ellipses (. )

Читайте также:  Opera browser on linux

—no-pager can be added to avoid invoking a pager when the output is an interactive terminal.

Could you explicit your answer somehow? Adding some explanation about the options, and don’t hesitate to format your answer!

Since this no longer works on my system, I’ve posted another answer that makes it posible to get the full logs via systemctl (with full support to journalctl’s options to boot). It’s a hack but it’s been working great for me so far.

Use journalctl to View Your System’s Logs

View journalctl without PagingPermalink To send your logs to standard output and avoid paging them, use the —no-pager option:

It’s not recommended that you do this without first filtering down the number of logs shown.

journalctl -u service-name.service

Show Logs within a Time RangePermalink Use the — since option to show logs after a specified date and time:

journalctl —since «2018-08-30 14:10:10»

Use the —until option to show logs up to a specified date and time:

journalctl —until «2018-09-02 12:05:50»

Combine these to show logs between the two times:

journalctl —since «2018-08-30 14:10:10» —until «2018-09-02 12:05:50»

Источник

Подскажите, как отобразить работу скрипта запущенного через systemctl?

Но иногда мне хочеться посмотреть в консоле на цикл скрипта и убедиться что он выводит именно print(«Привет мир») Подскажите какя команда для это преднозначенна?

Грубо говоря, пиши в пайп, периодически подключайся к нему и читай, что туда пишется.

Если у тебя включен и правильно настроен journald, то ты можешь подключиться к логу этого сервиса:

journalctl --follow --unit my-script.service 

(или, кратко, journalctl -f -u my-script )

Вредные советы. Если у ТСа systemctl status уже показывает вывод сервиса — то достаточно просто подключиться к журналу, незачем городить пайпы и прочие велосипеды.

Читайте также:  Linux команды консоли перезагрузка

intelfx ★★★★★ ( 17.11.19 20:29:08 MSK )
Последнее исправление: intelfx 17.11.19 20:29:39 MSK (всего исправлений: 2)

а, ну, да.. что-то я прочитал «systemd», а подумал «надо к демону подключаться» — отсюда и вредные советы 😉

sudo systemctl status my-script.service

Должно само показывать вывод, если ты не перенастраивал что-то в systemd. Я сталкивался с буферизацией вывода в python, чтобы не было этого нужно запускать скрипт в юните через python -u

goingUp ★★★★★ ( 17.11.19 20:48:38 MSK )
Последнее исправление: goingUp 17.11.19 20:57:52 MSK (всего исправлений: 2)

исчо есть красивое перенаправление стдоут в консольку.

StandardOutput=
Controls where file descriptor 1 (STDOUT) of the executed processes is connected to. Takes one of inherit, null, tty, journal, kmsg, journal+console, kmsg+console, file:path, append:path, socket or fd:name.

tty connects standard output to a tty (as configured via TTYPath=, see below). If the TTY is used for output only, the executed process will not become the controlling process of the terminal, and will not fail or wait for other processes to release the terminal.

баловался. стоит монитор на видном месте и какие-то строчки непонятные по нему бегают. несведущих весьма завораживает.

Источник

Оцените статью
Adblock
detector