Lab 15.6 Scheduling a Periodic Task with cron (need help understanding)
Hello,
Note: I am running Ubuntu 18.04.6 LTS as a VM
I need help understanding what I'm missing in order to complete this lab.
I ran two versions to test:
Version 1:- As instructed in the lab (only with exception that I created myjob.sh script on /home/amar/Desktop/ instead of /tmp/). However, nothing is printed to the terminal on scheduled time. Screenshot provided for reference
Version 2:- Similar to as instructed in the lab (with exception that myjob_v2.sh would write stdout to a file on Desktop). However, no file is created on scheduled time. Screenshot provided for reference
Please provide clarification in understanding what I'm missing.
Thank you,
Amar
Best Answers
-
Hi @cloud4amar,
1.- If the task is wide for all the system and/or users, so it makes sense to edit/work with /etc/crontab . You can use 'crontab -e' in that case, so it checks for the syntax.
2.- If the task is just for one user, you should use the user account to setup its own crontab. After all, who knows what the user is going to put in the crontab. So it's a matter of local security as well.
Regards,
Luis.0 -
Hello @luisviveropena,
Thank you for bringing those points to further clarify my understanding.
In addition, upon further careful look at the man page of crontab, I figured the issue was with mycrontab file. It did not end with a newline character. Now crontab is working as expected.
Screenshot reference:

Thank you for the support,
Amarpreet (amar)1 -
Hi @cloud4amar, as I mentioned, it makes sense when the crontab is needed to run for all the users, or for a system task. But if it's a job that a non privileged user, the best thing is to configure it in the user's crontab.
Regards,
Luis.0
Answers
-
Hi @cloud4amar,
Yeah, the message is not printing to the terminal, but you can modify the script a bit, so you can see this is working.
So, I tested it on Ubuntu 20.04.4 and I did the following:
1.- Modified the "myjob.sh" script (on /tmp/) to the following, so it will write to a file each time it runs:
!/bin/bash
echo Hello I am running $0 at $(date) >> /tmp/hi.txt
2.- Modified the crontab to it runs in a specific minute of your convenience, so you don't have to wait until it's 10 am to run:
crontab -l
48 * * * * /tmp/myjob.shSo I put '48' to run it on minute 48. You can adjust it to your needs/time.
3.- When it ran, I took a look to /tmp/hi.txt:
Hello I am running /tmp/myjob.sh at Ach Sak 26 11:48:01 -05 2022
So it's working

Note: on my distro the crontab job on the system is in the following path:
/var/spool/cron/crontabs/luis
You need to take a look at it with the user you are working.
I hope that helps

Regards,
Luis.0 -
Hello @luisviveropena,
I followed the lab instructions again with suggested modifications, however still no success.
Eventually, what worked for me is to edit the /etc/crontab file as root.
I believe it's still a valid solution to schedule tasks, right? Please provide feedback.
Here's the screenshot for reference:

Happy Holidays!
Thank you,
Amarpreet (amar)0
Categories
- All Categories
- 177 LFX Mentorship
- 177 LFX Mentorship: Linux Kernel
- 768 Linux Foundation IT Professional Programs
- 379 Cloud Engineer IT Professional Program
- 175 Advanced Cloud Engineer IT Professional Program
- 75 DevOps IT Professional Program - Discontinued
- 7 DevOps & GitOps IT Professional Program
- 101 Cloud Native Developer IT Professional Program
- 7.6K Training Courses & Learning Paths
- 4 AI & ML Training
- 1 Blockchain & Decentralized Identity Training
- 11 Cloud & Containers Training
- 1 Cybersecurity Training
- 2 DevOps & Site-Reliability Training
- 1 Linux Kernel Development Training
- 1 Networking Training
- 2 Open Source Best Practice Training
- 3 System Administration Training
- 1 System Engineering Training
- 1 Web & Application Development Training
- 796 Hardware
- 202 Drivers
- 68 I/O Devices
- 37 Monitors
- 95 Multimedia
- 173 Networking
- 91 Printers & Scanners
- 91 Storage
- 771 Linux Distributions
- 81 Debian
- 68 Fedora
- 23 Linux Mint
- 13 Mageia
- 24 openSUSE
- 151 Red Hat Enterprise
- 31 Slackware
- 13 SUSE Enterprise
- 356 Ubuntu
- 465 Linux System Administration
- 31 Cloud Computing
- 73 Command Line/Scripting
- Github systems admin projects
- 98 Linux Security
- 78 Network Management
- 101 System Management
- 46 Web Management
- 120 Mobile Computing
- 20 Android
- 85 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 395 Off Topic
- 121 Introductions
- 30 Study Material
- 1K Programming and Development
- 310 Kernel Development
- 692 Software Development
- 1K Software
- 400 Applications
- 182 Command Line
- 5 Compiling/Installing
- 69 Games
- 318 Installation
- Archived
- 183 Small Talk
- 2 LFD140 Class Forum
- 1.4K LFS258 Class Forum
Upcoming Training
-
August 20, 2018
Kubernetes Administration (LFS458)
-
August 20, 2018
Linux System Administration (LFS301)
-
August 27, 2018
Open Source Virtualization (LFS462)
-
August 27, 2018
Linux Kernel Debugging and Security (LFD440)