Reading: Here is a helpful guide on how to change the timezone on a Ubuntu system. Information on how to make the change from the command part is in the bottom section of the article..
We often need to perform a task repetitively or during off-peak times when we (and others) are not working. The cron system and at command enable scheduling such tasks to automatically run at some point in the future.
Before you begin, you might want to revert to your baseline snapshot. Be sure to leave a snapshot at the final version of your previous lab so you can return to that point in the future. Reverting to the baseline snapshot before each lab ensures that you can work on the new lab without suffering from any errors or problems that might exist in your previous work.
Using information in the link above, or some other online resource, change the timezone of your Ubuntu server to EST (-0500). You can use the timezone in New York City to do this.
The point of this step is to make interpreting times a little easier. Otherwise, you would have to constantly convert between familiar times (in the EST timezone) to UTC (Coordinated Universal Time), which is error-prone. Keep in mind that it is normal to run real servers on UTC time, particularly if they are servicing clients from all over the world.
As system administrators, we need to monitor the health of our systems. One way is to maintain a log of historical data captured from systems periodically. We can use such logs for automated alarms, or for baseline comparisons, or for future capacity-planning.
A good system health monitor is vmstat. In this task, create a cron job to capture the output of vmstat to a log file every 15 min. While any user can run vmstat, usually an IT team runs a server, so let's put this in root's crontab.
Finally, we need a date/time stamp on each row. The vmstat command doesn’t do that for you by default, so add a date/time stamp at the beginning of each line and then write vmstat’s output after that on the same line.
Hints:
The first two lines of vmstat contain header info, and the third line is an average since the machine was rebooted. You need to figure out how to get vmstat to print more than just the average statistics and then capture the last line of the output (4th line)
Write a script or just put the command in the crontab (it is possible to do with one command line if you’re good with shell syntax, but not necessary).
A good timestamp format is “[%F %T]” if you are using the date command.
Note: If you use crontab -e, you do not need to restart the cron service. However, if you put a new crontab in /etc/cron.d or if you edit /etc/crontab directly, you do need to restart the service. Be sure to justify your choice about how/where you created the crontab.
Let your cron run for an hour or two, so you have log output to prove it executed correctly every 15 minutes. After that you can disable the cron so it doesn’t run for the rest of the class (or not if you want to keep logging stats for some reason).
Let's show that any user can write a crontab. Pick one of the other users on your system (e.g., student). Write a shell script or a command to delete all files in ~/Pictures for that user that are "older than 2 weeks." The user wants to run this command daily to clean up old files.
To verify, touch some files in the Pictures directory you created to simulate old and new files. Set up cron to run one or two minutes from "now." Prove that the old pictures are removed as expected while newer files are not. You will probably need to read the touch man page to figure out how to simulate old pictures.
Let's pretend we have an issue where the logs from a performance monitor (sar or top or vmstat from Part 2) are showing that your server is regularly having issues at 3 a.m. Maybe it is a backup issue? Maybe it is a user issue? Maybe it is a network problem? We don't know, so we are going to run a monitor script right at 3 a.m. to see what's going on.
Create a top10 monitoring script by putting the following into a text file:
#!/bin/sh # top10 # show the top 10 processes by cpu usage # sort on col 3 ps aux | head -1 && ps aux | tail -n+2 | sort -rn -k3 | head -10
Call your text file something like top10.sh and be sure to make it executable.
Run this script from your home dir at two minutes past "now" and capture stdout into a text file. We are replicating how to capture text at 3 a.m. (while you are sleeping) and review the text on the next day. Verify it works as expected. Hint: this is not a crontab repeating command, it’s just a one-time scheduled command.
Now schedule the command to run at 3 a.m. and verify it is scheduled correctly (how do you check the scheduling queue?). You don’t actually have to keep your machine on so that it can run, just showing it is scheduled is enough.
For this lab submit a document that details the steps you took and the commands you used to complete the tasks above. The lab is worth 20 points.
Last Revised: 2025-02-14
© Copyright 2025 by Peter Chapin <peter.chapin@vermontstate.edu>