Linux Basics Lesson 35 of 38
Schedules, logs and packages
10 minutes
Learning goals
- Read the five time fields of a crontab line, and change a crontab without an editor.
- Filter the journal by service, priority, time and kernel with journalctl.
- Show with apt what is installed and which version it has.
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:
Example:
crontab -l
*/15 * * * * /home/lerner/bin/check-disk.sh*/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:
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 rootEvery 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:
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]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.
Task complete
Solution
crontab -l Why: */15 * * * * /home/lerner/bin/check-disk.sh: every 15 minutes, every hour, every day. Whether it really ran is in the journal, and that is two exercises further on.
See the solution? You get fewer XP for this task.
Start over? Files, folders and output go back to the start. Your hints stay.
Loading terminal …
Esc, then Tab leaves the terminal
Not done yet
Repeat: you have solved this task before.
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.
Task complete
Solution
crontab -l > cron.txt
echo '30 2 * * * /home/lerner/bin/check-disk.sh' >> cron.txt
crontab cron.txt Why: crontab FILE replaces the whole crontab. That is why the old line has to be in the file too. With > instead of >> in the second step, the job every 15 minutes would be gone.
Another way
(crontab -l; echo '30 2 * * * /home/lerner/bin/check-disk.sh') | crontab - One line instead of three, but without the file in between, which you could have looked at before installing it.
See the solution? You get fewer XP for this task.
Start over? Files, folders and output go back to the start. Your hints stay.
Loading terminal …
Esc, then Tab leaves the terminal
Not done yet
Repeat: you have solved this task before.
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.
Task complete
Solution
journalctl -u cron -n 10 Why: The last CMD line for lerner is from 09:15. Every quarter of an hour the same three lines, so the job is started. Whether the script itself succeeded is what its own output would say.
See the solution? You get fewer XP for this task.
Start over? Files, folders and output go back to the start. Your hints stay.
Loading terminal …
Esc, then Tab leaves the terminal
Not done yet
Repeat: you have solved this task before.
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.
Task complete
Solution
journalctl -p err Why: One error at 08:52, from the app, not from cron. -p err shows errors and everything worse, so a crit or an emerg would be there too.
See the solution? You get fewer XP for this task.
Start over? Files, folders and output go back to the start. Your hints stay.
Loading terminal …
Esc, then Tab leaves the terminal
Not done yet
Repeat: you have solved this task before.
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?
Task complete
Solution
apt show curl Why: 8.14.1-2+deb13u7 from trixie-security. The +deb13u7 is the seventh update of Debian 13 for this package. Compare it with the version named in the notice, and update with sudo apt update and sudo apt upgrade on a real server.
See the solution? You get fewer XP for this task.
Start over? Files, folders and output go back to the start. Your hints stay.
Loading terminal …
Esc, then Tab leaves the terminal
Not done yet
Repeat: you have solved this task before.
Next up: users and groups.
Quiz
-
Check works once you have chosen an answer.
-
Check works once you have chosen an answer.
-
Check works once you have chosen an answer.
Cards
-
Card 1 of 3
Tap the card or press Space to turn it over.
-
Card 2 of 3
Tap the card or press Space to turn it over.
-
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
What you can do now: crontab -l, journalctl -u cron -n 6, apt list --installed
+0 XP in this lesson
- Lesson 1: open
- Lesson 2: open
- Lesson 3: open
- Lesson 4: open
- Lesson 5: open
- Lesson 6: open
- Lesson 7: open
- Lesson 8: open
- Lesson 9: open
- Lesson 10: open
- Lesson 11: open
- Lesson 12: open
- Lesson 13: open
- Lesson 14: open
- Lesson 15: open
- Lesson 16: open
- Lesson 17: open
- Lesson 18: open
- Lesson 19: open
- Lesson 20: open
- Lesson 21: open
- Lesson 22: open
- Lesson 23: open
- Lesson 24: open
- Lesson 25: open
- Lesson 26: open
- Lesson 27: open
- Lesson 28: open
- Lesson 29: open
- Lesson 30: open
- Lesson 31: open
- Lesson 32: open
- Lesson 33: open
- Lesson 34: open
- Lesson 35: done
- Lesson 36: open
- Lesson 37: open
- Lesson 38: open
Cheat sheet
-
crontab -lshow your crontab -
crontab <file>install the file as the new crontab -
journalctl -u <unit> -n 20the last lines of one service -
journalctl -p erronly errors and worse -
apt list --installedinstalled packages with their versions
The most important command lines of this module on one A4 page, black and white, to print or keep on your phone.
- Download PDF (PDF, 20 KB)
- View as image (PNG, 67 KB)