csci 26 :: midterm 2 (due tues, apr 14, AT START OF CLASS)
Submitting your work: Complete this exercise on your own.

Fill in all of the "Answer" boxes, then print the answer grid that you see after you press "Prepare for printing".

Staple all pages together and submit to the instructor on the date listed above.

YOU MUST HAVE YOUR MIDTERM PRINTED WHEN YOU ARRIVE IN CLASS. YOU WILL NOT BE ALLOWED TO PRINT YOUR MIDTERM IN CLASS ON THE DAY IT IS DUE.

Questions:

This midterm covers all of the concepts you encountered on Daily Challenges 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, and 19.

Your name:
  1. Write the commands to perform each of the following actions:
    • change the owner of the file "midterm.dat" to "janedoe"
    • change the owner of the file "midterm.dat" to "johndoe" and the group to "person"
    • change the group of the file "midterm.dat" to "people"

    Answer:
  2. Write the command to set the mode/permissions of the file "midterm.dat" to the following permissions, using the octal representation:
    • user -- read, write, and execute
    • group -- read and write
    • other -- read

    Answer:
  3. Write the command to make the script "goodscript.sh" executable for user, group, and other, using symbolic representation. Do not alter the other permissions on the script.
    Answer:
  4. Briefly describe the contents of the /lib directory with respect to the File Hierarchy Standard (FHS).
    Answer:
  5. What directory on a Debian Wheezy system contains the system log files?
    Answer:
  6. Are shadow passwords the default on Debian installations? Where are shadow passwords stored on a Debian system?
    Answer:
  7. Answer the following questions about sudo:
    • what is the purpose of sudo?
    • how does a user become a sudoer?
    • what file contains configuration options for sudo?

    Answer:
  8. Write the command to create "countusers" as an alias to the command "who | wc -l".
    Answer:
  9. Which of the following configuration files is processed by your shell during an interactive login?
    • /etc/profile
    • ~/.bash_profile
    • ~/.bashrc

    Answer:
  10. Enter a complete bash script (including the "shebang" part) in the box below that does the following:
    • displays "STATUS REPORT" to the console
    • displays "There are __ files in your home directory." (fill in the blank with a count of the files in your home directory, using the ls and wc utilities and the "backtick" syntax)

    Answer:
  11. Enter a complete bash script (including the "shebang" part) in the box below that does the following:
    • display a prompt for the user that says "Enter a word describing your mood: "
    • read the user's entry into a variable named mood
    • display "I am glad you are feeling ____. Or not, if that is a bad or sad mood." (fill in the blank with the value of the variable mood you read in)

    Answer:
  12. Enter a complete bash script (including the "shebang" part, and using "if elif else") in the box below to do the following:
    • display a prompt for the user that says "Enter your favorite food: "
    • read the user's entry into a variable named favoriteFood
    • print the message "Yummy" if the value of the variable favoriteFood is "donut"
    • print the message "Yucky" if the value of the variable favoriteFood is "okra"
    • otherwise print the message "____ is an interesting choice" (fill in the blank with the value of the variable favoriteFood you read in)

    Answer:
  13. Enter a complete bash script (including the "shebang" part, and using "case") in the box below to do the following:
    • display a prompt for the user that says "Enter 1 or 2: "
    • read the user's entry into a variable named entry
    • print the message "One fish" if the value of the shell variable entry is 1
    • print the message "Two fish" if the value of the shell variable entry is 2
    • otherwise print the message "Red fish, blue fish"

    Answer:
  14. Enter a complete bash script (including the "shebang" part, and using "for" loop) in the box below to do the following:
    • process the output of an "all" file listing of the present working directory, one item at a time
    • for each item in the listing, if it a regular file, display the output of the wc command for the file, using wc defaults (i.e., no options)

    Answer:
  15. Enter a complete bash script (including the "shebang" part, and using "while" loop and "if elif else") in the box below to do the following:
    • declare a variable SECRET_NUMBER and assign it the value 42
    • declare a variable guess and assign it the value 0
    • repeat each of the following until the user guesses the correct number:
      • display a prompt for the user that says "Guess a number between 1-100: "
      • read the user's entry into a variable named guess
      • if the user's guess is too high, print the message "Too high"
      • else if the user's guess is too low, print the message "Too low"
      • else print "You got it!"

    Answer:
  16. Implement a shell function named ssh_me that requires exactly two arguments. If two arguments are supplied, the function will assume the first argument is a USER name, and the second argument is a HOST name, and it will execute the SSH command to connect USER to HOST. If two arguments are not supplied, the function will display an appropriate usage message.
    Answer:
  17. Implement a shell function named mock_me that requires exactly one argument. If one argument is supplied, the function will display the message "You should eat ____, not wear it." (fill in the blank with the argument supplied to the function). If one argument is not supplied, the function will display an appropriate usage message.
    Answer:
  18. What file controls system cron jobs?
    Answer:
  19. When will the following cron job run?
    */15 * * * * root script.sh
    Answer:
  20. Write the crontab commands to perform each of the following actions (use the "-u" option per your book's recommendation):
    • display the current crontab for your user
    • edit the current crontab for your user

    Answer:
  21. What is the primary file used on a Debian system to configure sources for APT packages?
    Answer:
  22. Write the apt-cache command to list all available packages associated with "gnome", limiting the search to names only (i.e., do not search package descriptions).
    Answer:
  23. Write the apt-get command to install the package "gimp".
    Answer:
  24. Write the command to perform the following action (using only top with options):
    • display real-time information about all processes owned by your user

    Answer:
  25. Write the commands to perform each of the following actions:
    • launch the script "script.sh" in the background (assume script.sh is in your present working directory)
    • display the PID of of "script.sh"
    • send SIGKILL to your "script.sh" process

    Answer:

Total points for this midterm exam:

500 points