Linux Up Skill - Day 10
Lesson ten of the Linux Up Skill Challenge is called “Getting the computer to do your work for you.” Automation is a topic I can always learn more about and spend more time with. The lesson starts off with Cron.
It starts with explaining the different ways to use Cron. It starts with crontab -l
to view my user level tasks. I get a result of no crontab for david
which is not surprising since we have not set any up in this course yet. I can look at root’s tasks with sudo crontab -l
which also produces no crontab for root
. Next we look at the system wide tasks via less /etc/crontab
and get the following output:
david@linux-up-skill:~$ less /etc/crontab # /etc/crontab: system-wide crontab # Unlike any other crontab you don't have to run the `crontab' # command to install the new version when you edit this file # and files in /etc/cron.d. These files also have username fields, # that none of the other crontabs do. SHELL=/bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed 17 * * * * root cd / && run-parts --report /etc/cron.hourly 25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily ) 47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
This is a great explanation of how Cron is working. I can look at the daily or weekly cron files to see what is being done for each period. For example ls /etc/cron.daily/
I get this output:
david@linux-up-skill:/etc$ ls /etc/cron.daily/ apache2 apt-compat dpkg man-db update-notifier-common apport bsdmainutils logrotate popularity-contest
Then I can look at each of those scripts to learn what each one does. This is fantastic and helping to demystify Cron for me. The lesson then mentions at
and anacron
but then says you will never use them. Ok, moving on then.
The lesson then moves on to systemd timers which is used to start and stop services but can also be used to run tasks at specific times. You can see what systemd
is up to with the command systemctl list-timers
:
david@linux-up-skill:~$ systemctl list-timers NEXT LEFT LAST PASSED > Tue 2022-06-21 15:15:18 EDT 2h 15min left Mon 2022-06-20 21:08:54 EDT 15h ago > Tue 2022-06-21 16:30:34 EDT 3h 30min left Mon 2022-06-20 18:03:33 EDT 18h ago > Tue 2022-06-21 18:28:47 EDT 5h 28min left Tue 2022-06-21 11:33:54 EDT 1h 26min > Tue 2022-06-21 20:16:14 EDT 7h left Tue 2022-06-21 02:14:33 EDT 10h ago > Wed 2022-06-22 00:00:00 EDT 10h left Tue 2022-06-21 00:00:54 EDT 12h ago > Wed 2022-06-22 00:00:00 EDT 10h left Tue 2022-06-21 00:00:54 EDT 12h ago > Wed 2022-06-22 06:43:10 EDT 17h left Tue 2022-06-21 06:54:54 EDT 6h ago > Wed 2022-06-22 10:32:05 EDT 21h left Tue 2022-06-21 10:32:05 EDT 2h 28min > Sun 2022-06-26 03:10:03 EDT 4 days left Sun 2022-06-19 03:10:33 EDT 2 days ag> Mon 2022-06-27 00:00:00 EDT 5 days left Mon 2022-06-20 00:00:47 EDT 1 day 12h> 10 timers listed. Pass --all to see loaded but inactive timers, too.
This has been a great explanation to help me get started with automating in Linux. It will be useful once I spin up some of my own servers to work on some automation scripts. What do you like to automate on your Linux servers?