CT320

Three headers follow: ! Long name of class !! Semester !!! R 1, replaced by the name of the current page.

CT320: Network and System Administration

Fall 2013

R 1

Links to the various pages for this class:

Wish I could do this: * Schedule

CT320 Recitation 1 (R1)

Group Project

Introduction to Shell Scripting

The purpose of this assignment is to get you started writing Linux scripts using the bash shell. You will create and edit a bash script in class that uses many of the features of shell scripts described in the lecture.

Part 1

Make sure you can login to the Linux system using the CT320 user and the password given to you be the instructor or teaching assistant. Make sure that you understand the Gnome desktop well enough to run the Firefox browser, file manager, and gedit and terminal programs.

Part 2

Practice redirection and pipes using the find and grep commands, as shown by the following sequence:

    $ cd /bin
    $ find . -print | grep dir
    $ find . -print | grep ch

Practice arranging output in order by name or size or date using the ls and sort commands, as shown by the following sequence:

    $ ls -l | sort -k 9
    $ ls -l | sort -k 5 -n

Practice splitting an output stream to the terminal and a file using the echo and tee commands, as shown by the following sequence:

    $ cd ~
    $ echo “This string should be displayed and written to the file” | tee string.txt
    $ cat string.txt

Practice splitting an output stream to the terminal and a file using the echo and tee commands, as shown by the following sequence:

    $ cd ~
    $ echo “This string should be displayed and written to the file” | tee string.txt

Practice operating on all of the files in a directory using the ls and chmod, in conjunction with xargs, as shown by the following sequence:

    $ mkdir temp
    $ cd temp
    $ echo “File 1” > File1.txt
    $ echo “File 2” > File2.txt
    $ echo “File 3” > File3.txt
    $ echo “File 4” > File4.txt
    $ ls -l
    $ ls | xargs chmod 666
    $ ls -l

Part 3

Write a script that does all of the following:

    # Students: name, name, ...
    # Ids: 8xx-xx-xxxx, 8xx-xx-xxxx, ...
    # Course: CT320
    # Assignment: Recitation R1
    # Date: YYYY-MM-DD

In addition to the previous requirements, the script must do the following:

  1. The unprotect action does not need to operate recursively.
  2. A loop must be used to perform the unprotect action.
  3. The list action should sort the files by file name.
  4. The delete action should work without prompting the user.
  5. The archive action should operate on the directory contents recursively.
  6. The archive action must create /tmp/archive if it does not exist.
  7. All output should be echoed to the file R1.log, creating a new file for each run.
  8. To perform all actions, the script must change to the specified directory.
  9. The script must change to the directory from which it was run before exiting.

Part 4

NOTE: You might want to make a backup copy of the “Test” directory before testing any commands in case your script intentionally or accidentally deletes files. Now test your script as follows:

  1. Create a directory in the ct320 home directory called “Test”.
  2. Create 5 files with names “File1.txt” through “File5.txt” in “Test”.
  3. Make each file contain its name as the contents.
  4. Create a subdirectory in “Test” called “Subtest”.
  5. Create 2 files with names “Subfile1.txt” and “Subfile2.txt” in “Subtest”.
  6. Examine the default protections of all directories and files in “Test”.
  7. Run the script with action equal to “unprotect”.
  8. Make sure all protections have changed to 777 (-rwxrwxrwx).
  9. Run the script with action equal to “list”, and examine the resulting listing.
  10. Run the script with action equal to “archive”, and check /tmp/archive.
  11. Run the script with action equal to “delete” and make sure “Test” is empty.

Part 5

You will now be shown how to turn your script file into the Recitation 1 drop box on RamCT. The lab is done in teams of two, but each student must submit to get credit.

Modified: 2013-09-04T11:10

User: Guest

Check: HTML CSS
Edit History Source
Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2015 Colorado State University
CS Building