OPS435 Lab 4 - Bash

From CDOT Wiki
Jump to: navigation, search

Fix this script and submit it in Blackboard.

#!/bin/bash
# Fix the syntax errors in this script so that at the end of it you get
# output similar to this (exact output will depend on your log files):
#
# Extracting cs-ssl-access_log-20150104.bz2
# Extracting cs-ssl-access_log-20150111.bz2
# Appending cs-ssl-access_log-20150104
# Appending cs-ssl-access_log-20150111
# andrew.smith: 38 hits.
# john.selmys: 4756 hits.
# peter.mcintyre: 146 hits.
#
# Note that you should be able to run your script multiple times.
#
# 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/
#
cd apache-logs-2015/

# Extract all the bz2 files
for FILE in `ls cs-ssl*.bz2`
do
  echo "Extracting $FILE"
  bunzip2 < $FILE > `basename $FILE .bz2`
done
 
# Concatenate all the log files into one file called "combined"
for FILE in `ls | grep -v combined`
do
  # Append to "combined" but only if it's an "ASCII text" type of file
done

# How many pages have been accessed for each of these teachers?
TEACHERS="andrew.smith john.selmys peter.mcintyre"
... loop each teacher ...
  echo "$TEACHER: "`grep $TEACHER combined | wc -l`" hits."