CT320: Network and System Administration

Fall 2018

HW 6

CT320 HW6: Eternal Vigilance!                


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 “observe”, 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 id command again, and inform you if anything has changed.                 

For example, observe date will probably change every time, unless you’re quick. However, we don’t expect observe id to change too often.                 


There are three cases:                 

  1. This particular command (and arguments) has never been executed before.
    Say so, and display the output of the command.
  2. This command (and arguments) produced the same output as before.
    Display nothing, because nothing changed. This is the normal, happy, case.
  3. This command (and arguments) produced different output than before.
    Say so, and show the difference between the old and new outputs using 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, observe itself 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 observe 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, then 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 ~/.observe.                 

Note that the command given to observe can contain all sort of special characters: spaces, stars, quotes, slashes, etc.                 

Sample Use from cron:                

Here are some examples of use from cron. If no changes occur, then observe produces no output. However, if changes do occur, then observe proudces output, which cron then mails to you.                 


    # 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:

    export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a



Use web checkin, or:                 

    ~ct320/bin/checkin HW6 observe

How to receive negative points:                 

Turn in someone else’s work.

User: Guest                 

Edit History Source

Modified: 2018-11-15T11:11                 

Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2018 Colorado State University
CS Building