Logging & Troubleshooting
Logging & Troubleshooting
7 interactive questions
Where are system logs stored and how do you read them?
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).
How do you filter journalctl by time and priority?
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".
How do you debug a command that fails silently?
strace -f -e trace=openat,access <cmd>— syscalls. 2.ltrace -f <cmd>— library calls. 3. Run withbash -x script.shfor script tracing. 4. Check exit code:echo $?.
What is logrotate and how do you configure it?
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.
How do you debug a system that won't boot?
- GRUB menu → edit kernel line → add
systemd.unit=emergency.targetorrd.break. 2. In emergency shell: mount/sysroot,chroot /sysroot. 3. Checkjournalctl -xb,dmesg -T,fsckdisks. 4. Fix fstab, initramfs, or grub config.
How do you find what's using a port or file?
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.
How do you trace system calls of a running process?
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.