Logging & Troubleshooting

0%
Loggingjournalctlsyslogrsysloglogrotatedebuggingstraceltrace

Logging & Troubleshooting

7 interactive questions

LoggingQuestion
journalctlsyslogrsysloglogrotatedebuggingstraceltrace

Where are system logs stored and how do you read them?

Click to reveal answer
LoggingAnswer

systemd: journalctl (binary, indexed). Flags: -u <unit> (service), -f (follow), -p err (priority), --since "1 hour ago". Traditional: /var/log/syslog, /var/log/messages (text, rotated by logrotate).

LoggingQuestion
journalctlsyslogrsysloglogrotatedebuggingstraceltrace

How do you filter journalctl by time and priority?

Click to reveal answer
LoggingAnswer

journalctl --since "2024-01-01" --until "2024-01-02" -p err..crit (errors and above). -p 0..3 = emerg/crit/err/warning. --since "1 hour ago".

LoggingQuestion
journalctlsyslogrsysloglogrotatedebuggingstraceltrace

How do you debug a command that fails silently?

Click to reveal answer
LoggingAnswer
  1. strace -f -e trace=openat,access <cmd> — syscalls. 2. ltrace -f <cmd> — library calls. 3. Run with bash -x script.sh for script tracing. 4. Check exit code: echo $?.
LoggingQuestion
journalctlsyslogrsysloglogrotatedebuggingstraceltrace

What is logrotate and how do you configure it?

Click to reveal answer
LoggingAnswer

Rotates, compresses, mails, and removes old logs. Config in /etc/logrotate.d/. Key options: daily/weekly, rotate N, compress, delaycompress, missingok, notifempty, create 0640 root adm, postrotate script to reload daemon.

LoggingQuestion
journalctlsyslogrsysloglogrotatedebuggingstraceltrace

How do you debug a system that won't boot?

Click to reveal answer
LoggingAnswer
  1. GRUB menu → edit kernel line → add systemd.unit=emergency.target or rd.break. 2. In emergency shell: mount /sysroot, chroot /sysroot. 3. Check journalctl -xb, dmesg -T, fsck disks. 4. Fix fstab, initramfs, or grub config.
LoggingQuestion
journalctlsyslogrsysloglogrotatedebuggingstraceltrace

How do you find what's using a port or file?

Click to reveal answer
LoggingAnswer

Port: ss -tulpn | grep :PORT or lsof -i :PORT. File: lsof /path/to/file or fuser -v /path/to/file. Kill with fuser -k /path.

LoggingQuestion
journalctlsyslogrsysloglogrotatedebuggingstraceltrace

How do you trace system calls of a running process?

Click to reveal answer
LoggingAnswer

strace -p <PID> -f -e trace=network (attach). strace -f -o output.txt <cmd> (from start). Filters: -e trace=file,network,process. ⚠️ Adds overhead; don't run on high-throughput prod without sampling.