CT320

CT320: Network and System Administration                

Fall 2017                

Bash I                

CT320 Bash Lab I                

Group Project                

You may work in pairs, if space demands.                 

Introduction to Shell Scripting                

The purpose of this assignment is to get you started writing Linux scripts using bash. 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 by the instructor or teaching assistant. Make sure that you understand the system well enough to run a browser, file manager, terminal and text editor.                 

Part 2                

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

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

Advanced students may realize that these pipelines can be reduced to single find statements.                 

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

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

Of course, there are probably ls options to accomplish the same ends.                 

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

    $ cd
    $ echo "Brush your teeth after every meal" | tee string.txt
    $ cat string.txt

Practice operating on all of the files in a directory using 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 a=rw
    $ ls -l

Part 3                

Write a script that does all of the following:

    # Students: name1, name2
    # Logins: login1, login2
    # Assignment: CT320 BashI
    # Date: YYYY-MM-DD

In addition to the previous requirements, the script must:                 

  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, in Z–A order.
  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 bscript.log, creating it anew for each run.
  8. To perform all actions, the script must change to the specified directory.
  9. The script must change back to the directory from which it was run before exiting.

Part 4                

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 its 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 dirs 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                

When you have tested your script, and it works, show your work to the TA.                 

Modified: 2017-09-07T16:38                 

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