In the previous assignment, we kept track of which files were appearing and disappearing. That was great, but it’s not enough. In the system administration business, you have to keep track of a lot of things:
If only there were a program to help you keep track of things. One that could … observe!
For this assignment, you will write a program called “
which helps you keep track of things. It can be a
bash script, a
perl script, or a
python script, but nothing else. This program is
useful for system monitoring. You run it with arguments,
from any directory, like this (
% is my prompt):
% ./observe id
That says to run the
id command, and note its output.
Then, later, if you run
observe id again, it will run the
command again, and inform you if anything has changed.
observe date will probably change every time,
unless you’re quick. However, we don’t expect
observe id to change
There are three cases:
diff. Also, update the saved output with the new, changed, output.
observe would typically be executed from
cron, where the output
gets mailed to you. Ensure that the output is sufficiently labeled so
that it makes sense, even out of context. Of course,
knows nothing about email—
observe simply produces output or not.
cron handles emailing the output to you.
observe takes a number of arguments, which will form a shell command.
All of these should work. Remember that
% is my prompt, yours
will be different.
% ./observe id % ./observe date +%c % ./observe cat /etc/passwd % ./observe "sed 's/:.*//' /etc/passwd | sort" % ./observe gcc --version % ./observe 'cd ~info; ls -ld m*' % ./observe echo a/b/c % ./observe echo abc % ./observe echo a b c
If the option
--debug is given before the command, then
will add debug output. It’s your choice for what that means, but it
must at least mention the full path where the output is stored.
If the option
--commands is given, with no other arguments,
observe will list the commands in the database.
The commands listed must be the same as they were entered—mangled
versions are not acceptable.
observe has to store the commands and results somewhere. For that
purpose, it will use the directory
~/.observe, which your program
must create as needed. How it actually stores the data under
~/.observe is up to you. You could have one big file under
~/.observe, a number of files, an entire hierarchical directory
structure, etc. You have to create
Note that the command given to
observe can contain all sort of
special characters: spaces, stars, quotes, slashes, etc.
Here are some examples of use from
cron. If no changes occur,
observe produces no output. However, if changes do occur,
observe proudces output, which
cron then mails to you.
SHELL=/bin/bash PATH=/bin:/usr/bin:~/bin # Ensure web server is working: */5 * * * * observe wget -qO- https://www.cs.colostate.edu/~applin/alphabet # Do my directories have proper permissions? # Use \% because cron interprets % specially. @hourly observe stat -c '\%A \%n' ~ ~/public_html ~/public_html/pmwiki # Compiler updates? @daily observe g++ --version @daily observe python3 --version # General paranoia @daily observe id @daily observe pwd @daily observe host $HOSTNAME @daily observe cat /etc/system-release @daily observe uname -r
If you encounter “STACK FRAME LINK OVERFLOW”, then try this:
echo bare two different commands.
pwdis only one command, even though it gives different results in different directories, so it’s a poor candidate for use with
$0(or its equivalent).
Use web checkin, or:
~ct320/bin/checkin HW6 observe
How to receive negative points: