Open main menu

CDOT Wiki β

Changes

OPS435 Lab 1 - Bash

3,018 bytes added, 02:23, 15 January 2016
Created page with 'FOCUS: Your first BASH program. == PART A - Perform the following steps == <ol> <li> Login to your linux system and open a terminal window. <li> Write down the output of the fo…'
FOCUS: Your first BASH program.

== PART A - Perform the following steps ==

<ol>
<li> Login to your linux system and open a terminal window.
<li> Write down the output of the following command:
<source lang='bash'>
echo $PATH
</source>
<li>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:
<source lang='bash'>
PATH=/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/lib/ast/bin:/home/$USER/bin:.
export PATH
</source>
<li>Close your terminal window and open a new one.
<li>Again write down the output of the following command:
<source lang='bash'>
echo $PATH
</source>
<li>Make a directory named bin in your HOME and change into it.
<li>Create a shell script with the following contents:
<source lang='bash'>

#!/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
</source>
<li>You should save this script inside your bin directory.
<li>Name it cleanup and give yourself execute permissions.
<li>Change back into your HOME directory.
<li>Run the script by typing in cleanup at the prompt and make a note of the output.
<li>Now ssh to a matrix server using the command:
<source lang='bash'>
ssh -CX matrix.senecac.on.ca
</source>
<li>Again run the cleanup script and make a note of its output.
<li>Examine the script and once you understand how it works, proceed to PART B.
</ol>

== PART B - Answer the following questions ==
and and email them to your teacher in ASCII text format. Be sure to follow your teacher's guidelines for submitting labs.
What is your full name and nine digit Seneca student ID?
What were the permissions you set on the script? Show the output of the "ls -l cleanup" command.
What was the PATH you set? Show the results of steps 2 and 5 from PART A.
Why is it important to place your PWD (shown as a dot) at the end of your path?
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.
Explain the purpose of creating a bin directory inside your HOME.
Besides HOME, PATH and USER name two other commonly used global variables and explain their purpose.
What is your Matrix quota? And how much have you used?