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
- 175 LFX Mentorship
- 175 LFX Mentorship: Linux Kernel
- 745 Linux Foundation IT Professional Programs
- 372 Cloud Engineer IT Professional Program
- 168 Advanced Cloud Engineer IT Professional Program
- 73 DevOps IT Professional Program - Discontinued
- 3 DevOps & GitOps IT Professional Program
- 98 Cloud Native Developer IT Professional Program
- 7.6K Training Courses & Learning Paths
- AI & ML Training
- Blockchain & Decentralized Identity Training
- Cloud & Containers Training
- Cybersecurity Training
- DevOps & Site-Reliability Training
- Linux Kernel Development Training
- Networking Training
- Open Source Best Practice Training
- System Administration Training
- System Engineering Training
- Web & Application Development Training
- 2 LFD103-JP クラス フォーラム
- 4 LFD210-CN Class Forum
- 764 LFD259 Class Forum
- 681 LFS101 Class Forum
- 2 LFS158-JP クラス フォーラム
- 162 LFS207 Class Forum
- 3 LFS207-DE-Klassenforum
- 4 LFS207-JP クラス フォーラム
- 61 LFS241 Class Forum
- 52 LFS242 Class Forum
- 42 LFS243 Class Forum
- 19 LFS244 Class Forum
- 4 LFS250-JP クラス フォーラム
- 166 LFS253 Class Forum
- 19 LFS256 Class Forum
- 1.4K LFS258 Class Forum
- 165 LFS261 Class Forum
- 26 LFS267 Class Forum
- 792 Hardware
- 202 Drivers
- 68 I/O Devices
- 37 Monitors
- 95 Multimedia
- 173 Networking
- 91 Printers & Scanners
- 87 Storage
- 768 Linux Distributions
- 81 Debian
- 67 Fedora
- 22 Linux Mint
- 13 Mageia
- 24 openSUSE
- 150 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
- 105 Mobile Computing
- 18 Android
- 72 Development
- 1.2K New to Linux
- 1K Getting Started with Linux
- 392 Off Topic
- 121 Introductions
- 181 Small Talk
- 29 Study Material
- 944 Programming and Development
- 310 Kernel Development
- 616 Software Development
- 977 Software
- 369 Applications
- 182 Command Line
- 5 Compiling/Installing
- 68 Games
- 317 Installation
- Archived
- 2 LFD140 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)