CS 480-M01 Linux System Administration - CRN 60315 - Fall 2021
[Home]     [Syllabus]     [Notes]     [Grades]

HW 4 - CS 480 M01 Fall 2022

CS 480 M01 Fall 2022 - Homework Assignment #4

Due: 11:59 PM, Tuesday, Oct 4 2022
Assignment:

Points: 95 points total

  1. 15 pts : Read all man pages listed below (from sections 1 , 5, or 8; try the commands, look into the files, ... while reading) and in a short paragraph (3-5 lines per man page in your words - do not just copy parts of the man page) describe what is each of them for. Also, for the commands choose an extra option (not the help nor version options) and in few more lines describe situations in which you would use the selected option. In case of the commands with long man pages and many options choose at least two extra options and describe situations in which you would use them.
    1. at
    2. cron
    3. crontab ( config file )
    4. date
    5. journalctl
    6. ps
    7. sleep
    8. systemctl
    9. systemd
    10. systemd.service
    11. trap
    12. uptime
    13. w

Each exercise below is to be implemented on your cs480 virtual host. Every question asked needs to be answered in your assignment report. For every exercise below describe in sufficient detail the whole process and explain what you did to accomplish the task. Make sure that you list and discuss all important steps made, commands used together with their options, and problems encountered.

  1. 7 pts
    1. Create a simple shell script state.sh that will append info listed below into /tmp/state.log file:
      • current date and time
      • current load and users logged in
      • all processes running on the machine (long listing that, among other info, includes PID and PPID of each process )
    2. Create a cron job that will execute this script every 5 minutes (the state info gets appended into file /tmp/state.log every five minutes)
  2. 7 pts
    Create a new script movelog.sh and another crontab entry so that
    1. The movelog.sh script will
      • move the /tmp/state.log file into file named statelog.YYYYMMDD where YYYYMMDD is the current date (statelog.20220930, statelog.20221001, ...) and
      • removes old statelog.YYYYMMDD files that are 2 or more weeks old
    2. each statelog.YYYMMDD file has the state info (date, users, processes) stored every 5 minutes for the whole day (from midnight to the next midnight)
  3. 3 pts: Install GNOME
    yast -> Software mngmt -> Filter : Patterns -> and add the GNOME Desktop Environment (X11)
  4. 3 pts: Without using yast (you cannot use yast/yast2) modify your system to have the graphical interface as the default target.
  5. 15 pts: Write a simple Bash shell script /root/trap.sh which will
    1. Write its process ID into the file /var/run/trap.pid .
    2. Append one line of a text into the file /root/trap.log.
      The line will include the shell's current name and process ID followed by the current date as shown here:
      ./trap.sh [4441] started on Mon Sep 26 10:04:54 MDT 2022
    3. Trap all these signals: INT, QUIT, HUP, TERM , USR1, USR2 and write a message about it into the log file. Also,
      • Once the TERM signal is received the shell will remove the /var/run/trap.pid and exit.
      • The shell will continue to run when the other signals are received.
    4. Append the messsage "./trap.sh [PID] time tick ... DATE" into the /root/trap.log every 10 seconds.
      The DATE and PID are to be the actual current date and process ID of the running process.

    Example of the log file content:

    Here is an example of a script that uses trap :
  6. 10 pts: Create and configure new "service" trap_test.service that will excute the trap.sh.
    Create the /etc/systemd/system/trap_test.service unit file and use systemctl command to add the service among services in the graphical and multi-user targets.
    The command systemctl will start and stop the "service" (systemctl start trap_test.service and systemctl stop trap_test.service).
  7. 20 points
    Write a shell (/bin/sh) script which checks its options / arguments and prints out the result of this check.
    If the check fails then the usage message is also printed.
    Make sure that the script follows the best practices including that it provides meaningful exit code (0=success, nonzero=failure).

    -i and -n are optional but only one of these can be submitted (cannot be used together) and it has to be on the line prior to any user name
    -i means interactive mode (this is the default mode if none is specified)
    -n   means non-interactive mode
    USER parameter is mandatory but can repeat (more then one user names may be specified)

    Script prints out if it runs in interactive or in non-interactive mode. It also checks all user names and makes sure that every user name matches this regular expression: '^[a-z][a-z0-9_]*$'
    (Write and execute the script on your cs480 virtual host and submit a transcript of the session showing your script responding correctly to all of the tests as shown in the example below.)

  8. Example:

NOTE: Your solutions to all of the exercises above must be implemented, tested, and execute correctly on your cs480 virtual machine. Among your attachments (as part of the tar.bz2 file) submit also transcript files showing the correct execution of the commands / scripts as you executed them on your cs480 virtual machine. You can use the script command to record the session and submit the resulting files (4.4_trascript.txt, ...) with your homework assignment as part of your bz2 file submited into your directory under /home/CS480.

Submitted files, overall quality, length, and feedback:

  1. 5 pts : Submit all relevant files you modified during the lab (into the /home/CS480/yourcsloginname directory as part of the tar.bz2 file) . Exactly two files need to be submitted: One file being your report in PDF is to be submitted on the Blackboard. The other file is the tar.bz2 file containing everything else and it gets submitted into /home/CS480 (Pack the files together using tar and bzip2, and copy them using scp from your computer into your cs account )
  2.  10 pts - Submit your report as a PDF document through learn.nmsu.edu and all supporting documents, programs, and execution transcripts as part of the tar.bz2 file in your directory under /home/CS480. The report has to contain answers to all questions above, and for the practical problems on your computer describe in detail choices you made, difficulties you encountered, and how did you deal with them.
  3. 5 pts - Feedback:In the last paragraph of your report estimate how much time you spent on this assignment. Describe what was hard, easy, interesting, boring or confusing.

Please remember the submission requirements: