![Journalctl/시스템 로그 "사용자 1000 덤프 코어의 프로세스 1234(프로세스 이름)" 메시지를 별도의 파일로 추출합니다.](https://linux55.com/image/215932/Journalctl%2F%EC%8B%9C%EC%8A%A4%ED%85%9C%20%EB%A1%9C%EA%B7%B8%20%22%EC%82%AC%EC%9A%A9%EC%9E%90%201000%20%EB%8D%A4%ED%94%84%20%EC%BD%94%EC%96%B4%EC%9D%98%20%ED%94%84%EB%A1%9C%EC%84%B8%EC%8A%A4%201234(%ED%94%84%EB%A1%9C%EC%84%B8%EC%8A%A4%20%EC%9D%B4%EB%A6%84)%22%20%EB%A9%94%EC%8B%9C%EC%A7%80%EB%A5%BC%20%EB%B3%84%EB%8F%84%EC%9D%98%20%ED%8C%8C%EC%9D%BC%EB%A1%9C%20%EC%B6%94%EC%B6%9C%ED%95%A9%EB%8B%88%EB%8B%A4..png)
이것은 간단한 질문입니다.
에서 덤프된 각 프로세스에 대한 디버깅 정보가 포함된 별도의 파일과 같은 개요를 원합니다 journalctl
.
다음은 샘플 출력입니다.
Jan 17 12:49:45 localhost systemd-coredump[137987]: [
답변1
이유는 묻지 마세요. 하지만 journalctl _COMM=systemd-coredump
작동하지 않습니다. -- No entries --
. 별거 아니야.
JSON 출력을 사용하면 더 쉽게 수행할 수 있다고 확신합니다. 하지만 그러려면 jq
출력을 소비하고 구문 분석해야 하지만 저는 적절한 프로그래머가 아니기 때문에 awk
JSON을 사용하기로 결정했습니다. 이것이 내가 얻는 것입니다:
#! /bin/bash
journalctl --output=short-unix | awk '{
if ($1 ~ /^[0-9]/) {
if ( found == 1 && fname != "") system("touch -d @"unixts" "fname)
found=0
}
if ($0 ~ "dumped core") { # extract timestamp and process name and generate a filename
split($1, arr , ".")
if(arr[1] != "") unixts=arr[1]
psta=index($0, "(")
pend=index($0, ")")
pname=substr($0, psta+1, pend-psta-1)
fname=pname"-"unixts".txt"
found=1
}
if (found == 1) print $0 >> fname
}'
따라서 파일을 쉽게 볼 수 있으며 해당 로그 이벤트와 동일한 타임스탬프를 갖습니다.
$ ls -la
drwxr-xr-x. 2 root root 740 Jan 20 13:12 .
drwxrwxrwt. 22 root root 820 Jan 20 13:12 ..
-rw-r--r--. 1 root root 105937 Jan 14 19:55 chrome-1673726131.txt
-rw-r--r--. 1 root root 73845 Jan 13 22:20 xfce4-panel-1673648402.txt
-rw-r--r--. 1 root root 73853 Jan 14 18:05 xfce4-panel-1673719532.txt
-rw-r--r--. 1 root root 72205 Jan 16 15:33 xfce4-panel-1673883202.txt
-rw-r--r--. 1 root root 73845 Jan 17 12:49 xfce4-panel-1673959785.txt
-rw-r--r--. 1 root root 62702 Jan 10 08:31 xfce4-screensav-1673339519.txt
-rw-r--r--. 1 root root 62577 Jan 10 08:32 xfce4-screensav-1673339524.txt
-rw-r--r--. 1 root root 62702 Jan 11 11:13 xfce4-screensav-1673435632.txt
-rw-r--r--. 1 root root 62577 Jan 11 11:14 xfce4-screensav-1673435640.txt
이것이 다른 사람들에게도 유용하기를 바랍니다.