terminal.cab

Linux Basics Lesson 35 of 38

guestLevel 1Badges and progress0/100 XP, XP to the next levelStreak0

Schedules, logs and packages

10 minutes

Learning goals

crontab: jobs on a schedule

cron starts commands at fixed times. Each user has a crontab, a list of jobs, one per line: five time fields, then the command. The fields are minute, hour, day of the month, month and day of the week. * means every value:

crontab -l

Purpose: Shows, installs and deletes your schedule of jobs.

Syntax: crontab -l | crontab FILE | crontab -r

Options:

  • -l list the crontab
  • FILE, - install FILE, or the lines from a pipe, as the new crontab
  • -r delete the whole crontab, without asking

Example:

crontab -l
*/15 * * * * /home/lerner/bin/check-disk.sh

in the glossary: crontab

*/15 in the minute field means every 15 minutes, all day long. A few more: 0 3 * * * is every day at 03:00, 0 9 * * 1-5 is at 09:00 from Monday to Friday, 30 2 1 * * is at 02:30 on the first of each month.

The usual way to change your crontab is crontab -e, which opens it in an editor. The editor arrives with the Vim path. Here crontab -e gives a hint. Without an editor, you take three steps: save the crontab into a file, add a line, install the file:

crontab -l > cron.txt
echo '30 2 * * * /home/lerner/bin/check-disk.sh' >> cron.txt
crontab cron.txt
crontab -l
*/15 * * * * /home/lerner/bin/check-disk.sh
30 2 * * * /home/lerner/bin/check-disk.sh

A pipe does the same in one line. crontab - reads the new crontab from it:

(crontab -l; echo '0 4 * * 0 /home/lerner/bin/check-disk.sh') | crontab -
crontab -l
*/15 * * * * /home/lerner/bin/check-disk.sh
0 4 * * 0 /home/lerner/bin/check-disk.sh

Mind the quotes. Without them, the shell replaces every * with the names of the files in the folder before echo even sees it:

echo 0 3 * * * backup.sh
0 3 Documents archive bin logs notes.txt projects Documents archive bin logs notes.txt projects Documents archive bin logs notes.txt projects backup.sh

And give the command with its full path. cron starts jobs with a tiny PATH, /usr/bin:/bin, and reads neither ~/.profile nor ~/.bashrc. A command that works by hand can be "not found" at 03:00.

journalctl: what happened

On Debian 13, the logs of services, of cron and of the kernel go to the journal of systemd. journalctl reads it, and you narrow it down. -u picks one service, -n the last lines:

journalctl -u cron -n 6

Purpose: Reads the journal of systemd, filtered as you like.

Syntax: journalctl [-u UNIT] [-p PRIORITY] [-n N] [--since TIME] [-k]

Options:

  • -u, -k only this service, only the kernel
  • -p err only errors and worse
  • -n, --since the last N lines, everything since a time

Example:

journalctl -u cron -n 6
Oct 17 09:15:01 web-01 CRON[7378]: pam_unix(cron:session): session opened for user lerner(uid=1000) by lerner(uid=0)
Oct 17 09:15:01 web-01 CRON[7379]: (lerner) CMD (/home/lerner/bin/check-disk.sh)
Oct 17 09:15:01 web-01 CRON[7378]: pam_unix(cron:session): session closed for user lerner
Oct 17 09:17:01 web-01 CRON[7385]: pam_unix(cron:session): session opened for user root(uid=0) by root(uid=0)
Oct 17 09:17:01 web-01 CRON[7386]: (root) CMD (cd / && run-parts --report /etc/cron.hourly)
Oct 17 09:17:01 web-01 CRON[7385]: pam_unix(cron:session): session closed for user root

in the glossary: journalctl

Every 15 minutes the same three lines: cron opens a session for lerner, runs the command, closes the session. lerner may read the journal because the account is in the group adm. Further filters:

journalctl -p err
Oct 17 08:52:13 web-01 python3[2114]: ERROR db timeout after 5000ms
journalctl -u cron --since 09:10
Oct 17 09:15:01 web-01 CRON[7378]: pam_unix(cron:session): session opened for user lerner(uid=1000) by lerner(uid=0)
Oct 17 09:15:01 web-01 CRON[7379]: (lerner) CMD (/home/lerner/bin/check-disk.sh)
Oct 17 09:15:01 web-01 CRON[7378]: pam_unix(cron:session): session closed for user lerner
Oct 17 09:17:01 web-01 CRON[7385]: pam_unix(cron:session): session opened for user root(uid=0) by root(uid=0)
Oct 17 09:17:01 web-01 CRON[7386]: (root) CMD (cd / && run-parts --report /etc/cron.hourly)
Oct 17 09:17:01 web-01 CRON[7385]: pam_unix(cron:session): session closed for user root
journalctl -k
Oct 12 06:00:00 web-01 kernel: Linux version 6.12.48+deb13-amd64 (debian-kernel@lists.debian.org) (x86_64-linux-gnu-gcc-14 (Debian 14.2.0-19) 14.2.0, GNU ld (GNU Binutils for Debian) 2.44) #1 SMP PREEMPT_DYNAMIC Debian 6.12.48-1 (2026-09-20)
Oct 12 06:00:00 web-01 kernel: Command line: BOOT_IMAGE=/boot/vmlinuz-6.12.48+deb13-amd64 root=/dev/sda1 ro quiet
Oct 12 06:00:01 web-01 kernel: EXT4-fs (sda1): mounted filesystem 3f1c2a9e-7d41-4b8a-9c55-1e2f0a6b7c3d ro with ordered data mode. Quota mode: none.
Oct 12 06:00:02 web-01 kernel: EXT4-fs (sda1): re-mounted 3f1c2a9e-7d41-4b8a-9c55-1e2f0a6b7c3d r/w.
Oct 17 09:04:40 web-01 kernel: TCP: request_sock_TCP: Possible SYN flooding on port 0.0.0.0:80. Sending cookies.

-p err shows only errors and worse, --since everything from a time on, -k only the kernel. journalctl -u app -f follows a service live, like tail -f. Here -f gives a hint: following live comes later in the simulator.

Older guides search /var/log/syslog. A Debian 13 system without the package rsyslog has no such file, and everything is in the journal. On RHEL and Rocky Linux, cron also writes to /var/log/cron.

apt: what is installed

apt manages the packages on Debian and Ubuntu. It can also simply show them:

apt list --installed

Purpose: Shows the packages of a Debian or Ubuntu system, and installs them.

Syntax: apt list --installed | apt show PACKAGE | apt search WORD

Options:

  • list --installed every installed package with its version
  • show the details of one package
  • update, upgrade load the lists, then install the updates, both with sudo

Example:

apt list --installed
Listing... Done
adduser/stable,now 3.152 all [installed,automatic]
apt/stable,now 3.0.3 amd64 [installed,automatic]
bash/stable,now 5.2.37-2+b10 amd64 [installed,automatic]
bind9-dnsutils/stable-security,now 1:9.20.30-1~deb13u1 amd64 [installed]
coreutils/stable,now 9.7-3 amd64 [installed,automatic]
cron/stable,now 3.0pl1-197 amd64 [installed]
curl/stable-security,now 8.14.1-2+deb13u7 amd64 [installed]
iproute2/stable,now 6.15.0-1 amd64 [installed]
iputils-ping/stable,now 3:20240905-3 amd64 [installed]
passwd/stable,now 1:4.17.4-2 amd64 [installed,automatic]
procps/stable,now 2:4.0.4-9 amd64 [installed]
psmisc/stable,now 23.7-2 amd64 [installed]
rsync/stable-security,now 3.5.0+ds1-0+deb13u1 amd64 [installed]
sudo/stable-security,now 1.9.16p2-3+deb13u2 amd64 [installed]
systemd/stable,now 257.13-1~deb13u1 amd64 [installed]
util-linux/stable,now 2.41.5-0+deb13u1 amd64 [installed,automatic]

in the glossary: apt

Name, source, version, and automatic for packages that came in as a dependency. apt show curl shows the details of one package, apt search nginx searches the descriptions. The warning about the interface appears when the output goes into a pipe or a file. It is meant for scripts.

apt update loads the current package lists, apt upgrade then installs the updates, and apt install adds new packages. All three change the system and need root: as lerner they end with an error message about the lock, and sudo is not on this page. Installing packages comes in the LPIC-1 path. On RHEL and Rocky Linux the same tool is called dnf, on Arch pacman.

cat, grep and sed are not loaded on this page. cat and grep answer with command not found, sed with a hint. crontab -l shows what is in the crontab, and that is enough here.

Practice

Terminal task 1/5

Does the disk check still run? Show your crontab.

Task 1/5: Does the disk check still run? Show your crontab.

Does the disk check still run? Show your crontab.

Loading terminal …

lerner@web-01: ~bash
lerner@web-01:~$

Esc, then Tab leaves the terminal

Not done yet

Fill the gap

The crontab line 0 3 * * * backup.sh runs every day at in the morning (hh:mm).

The crontab line 0 3 * * * backup.sh runs every day at … in the morning (hh:mm).

Check works once you have typed an answer.

Terminal task 2/5

Add a second job without an editor. /home/lerner/bin/check-disk.sh should also run every day at 02:30. The job every 15 minutes stays.

Task 2/5: Add a second job without an editor. /home/lerner/bin/check-disk.sh should also run every day at 02:30. The job every 15 minutes stays.

Add a second job without an editor. /home/lerner/bin/check-disk.sh should also run every day at 02:30. The job every 15 minutes stays.

Loading terminal …

lerner@web-01: ~bash
lerner@web-01:~$

Esc, then Tab leaves the terminal

Not done yet

Terminal task 3/5

Did cron really start the check? Show the last lines that the service cron wrote to the journal.

Task 3/5: Did cron really start the check? Show the last lines that the service cron wrote to the journal.

Did cron really start the check? Show the last lines that the service cron wrote to the journal.

Loading terminal …

lerner@web-01: ~bash
lerner@web-01:~$

Esc, then Tab leaves the terminal

Not done yet

Terminal task 4/5

What went wrong today? Show only the errors in the journal.

Task 4/5: What went wrong today? Show only the errors in the journal.

What went wrong today? Show only the errors in the journal.

Loading terminal …

lerner@web-01: ~bash
lerner@web-01:~$

Esc, then Tab leaves the terminal

Not done yet

Terminal task 5/5

A security notice is about curl. Which version of curl is installed?

Task 5/5: A security notice is about curl. Which version of curl is installed?

A security notice is about curl. Which version of curl is installed?

Loading terminal …

lerner@web-01: ~bash
lerner@web-01:~$

Esc, then Tab leaves the terminal

Not done yet

Next up: users and groups.

Quiz

  1. Question 1 of 3Which crontab line runs a job every Monday at 07:00?

    Check works once you have chosen an answer.

  2. Question 2 of 3report.sh works when you type it, but as a cron job it ends with "not found". What is the most likely reason?

    Check works once you have chosen an answer.

  3. Question 3 of 3On a Debian 13 server without rsyslog, where do you find the lines of cron?

    Check works once you have chosen an answer.

Cards

  1. Card 1 of 3

    Tap the card or press Space to turn it over.

  2. Card 2 of 3

    Tap the card or press Space to turn it over.

  3. Card 3 of 3

    Tap the card or press Space to turn it over.

End of the lesson

Still open: 6 exercises, 3 quiz questions

Next: lesson 36, Users and groups (8 min)

What you can do now: crontab -l, journalctl -u cron -n 6, apt list --installed

+0 XP in this lesson

  1. Lesson 1: open
  2. Lesson 2: open
  3. Lesson 3: open
  4. Lesson 4: open
  5. Lesson 5: open
  6. Lesson 6: open
  7. Lesson 7: open
  8. Lesson 8: open
  9. Lesson 9: open
  10. Lesson 10: open
  11. Lesson 11: open
  12. Lesson 12: open
  13. Lesson 13: open
  14. Lesson 14: open
  15. Lesson 15: open
  16. Lesson 16: open
  17. Lesson 17: open
  18. Lesson 18: open
  19. Lesson 19: open
  20. Lesson 20: open
  21. Lesson 21: open
  22. Lesson 22: open
  23. Lesson 23: open
  24. Lesson 24: open
  25. Lesson 25: open
  26. Lesson 26: open
  27. Lesson 27: open
  28. Lesson 28: open
  29. Lesson 29: open
  30. Lesson 30: open
  31. Lesson 31: open
  32. Lesson 32: open
  33. Lesson 33: open
  34. Lesson 34: open
  35. Lesson 35: done
  36. Lesson 36: open
  37. Lesson 37: open
  38. Lesson 38: open
1 of 38

Next: lesson 36, Users and groups (8 min) That's enough for today

Path complete

You finished all 38 lessons of Linux Basics.

Back to the path

Cheat sheet

The most important command lines of this module on one A4 page, black and white, to print or keep on your phone.