OPS435 Lab 3 - Bash
Revision as of 12:32, 22 August 2017 by Andrew (talk | contribs) (Andrew moved page OPS435 Lab 3 to OPS435 Lab 3 - Bash)
Get the following scripts working and submit them via Blackboard:
Part 1
#!/bin/bash
# Fix this script so that when you run it it will tell you whether
# there is more or less than WARNING_THRESHOLD percent available disk space
#
DEVICE_TO_CHECK=/dev/sda1
WARNING_THRESHOLD=30
PERCENT_USED=`df | ... | ... | ...`
if [[ $PERCENT_USED $WARNING_THRESHOLD ]]
DEVICE_NAME=`df | ... | ...`
MOUNT_POINT=`df | grep $DEVICE_TO_CHECK | awk '{print $NF; }'`
echo "Device ... mounted on ??? is low on free disk space!"
otherwise
echo "There is plenty of free disk space."
fi
Part 2
#!/bin/bash
# Fix this script so that it will ask the user for the name of a file to
# extract and extract that file.
#
# Do this step manually:
# Create the directory apache-logs-2015 and download some files into it from
# http://matrix.senecacollege.ca/~andrew.smith/scs-logs-s015/
#
echo "Please choose one of the following files to extract: "
cd apache-logs-2015
...
echo -n "Your choice: "
read something
echo "Extracting to "`basename $CHOSENNAME .bz2`
bunzip2 < $CHOSENNAME
# If the previous command worked:
echo "All done."
# If the previous command didn't work:
echo "Something didn't work!"
exit 2
Notes
Rememeber that every program that runs returns a code - zero for success, non-zero for failure. There is a variable that holds the return code from the previously run command.