OPS435 Lab 1 - Bash

From CDOT Wiki
Revision as of 02:35, 15 January 2016 by Andrew (talk | contribs) (PART B - Answer the following questions)
Jump to: navigation, search

FOCUS: Your first BASH program.

PART A - Perform the following steps

  1. Login to your linux system and open a terminal window.
  2. Write down the output of the following command:
    echo $PATH
  3. Edit your .bashrc file (located in your HOME directory) and set up your PATH by adding the following lines at the end of the file:
    PATH=/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/lib/ast/bin:/home/$USER/bin:.
    export PATH
  4. Close your terminal window and open a new one.
  5. Again write down the output of the following command:
    echo $PATH
  6. Make a directory named bin in your HOME and change into it.
  7. Create a shell script with the following contents:
    #!/bin/bash
    # BASH script to free up disk space by deleting no longer needed files
    
    echo "Disk space in use by this account: $(du -sh ~/ | cut -f1)"
    echo
    echo This program will free up disk space used by the KDE help system and Firefox 
    echo cache, terminate Firefox, delete your Beagle index, and release any Firefox
    echo -e "lock files. OK to proceed? (Y/N) \c"
    read LINE
    
    if echo $LINE | grep -qi Y
    then
    	rm ~/.kde/share/apps/khelpcenter/index/* >/dev/null 2>&1
    	rm ~/.mozilla/firefox/*/Cache/* >/dev/null 2>&1
    	killall firefox firefox-bin >/dev/null 2>&1
    	find ~/.mozilla -name '*lock*' -exec rm {} \; >/dev/null 2>&1
    	rm -rf ~/.beagle >/dev/null 2>&1
    	echo "Cleanup complete -- disk space used by your account: $(du -sh ~/ | cut -f1)"
    else
    	echo "Cleanup aborted"
    fi
  8. You should save this script inside your bin directory.
  9. Name it cleanup and give yourself execute permissions.
  10. Change back into your HOME directory.
  11. Run the script by typing in cleanup at the prompt and make a note of the output.
  12. Now ssh to a matrix server using the command:
    ssh -CX matrix.senecac.on.ca
  13. Again run the cleanup script and make a note of its output.
  14. Examine the script and once you understand how it works, proceed to PART B.

PART B - Answer the following questions

  • And submit the answers in ASCII text format. Be sure to follow your teacher's guidelines for submitting labs.
  • The following all need to be included in your submission:
    1. What is your full name and nine digit Seneca student ID?
    2. What were the permissions you set on the script? Show the output of the "ls -l cleanup" command.
    3. What was the PATH you set? Show the results of steps 2 and 5 from PART A.
    4. Why is it important to place your PWD (shown as a dot) at the end of your path?
    5. What version of BASH did you use to run the script? Hint: the bash shell is like any other command (like ls, mv, cat, etc...). Use the man command (i.e. the "man pages") to get help regarding the bash shell and search how to determine the version.
    6. Explain the purpose of creating a bin directory inside your HOME.
    7. Besides HOME, PATH and USER name two other commonly used global variables and explain their purpose.