Difference between revisions of "CSC220 Homework 1 Solutions 2010"

From dftwiki3
Jump to: navigation, search
(Created page with '--~~~~ ---- =allUsersByDate2.sh= <code><pre> #! /bin/bash # allUsersByDate2.sh # Julia Burch # September 22, 2010 # Like the first script, this one outputs all the users in the …')
 
Line 8: Line 8:
 
# Julia Burch
 
# Julia Burch
 
# September 22, 2010
 
# September 22, 2010
# Like the first script, this one outputs all the users in the /Users directory by date of their last access. This time, only usernames are visible.  
+
# Like the first script, this one outputs all the users in the /Users
 +
# directory by date of their last access. This time, only usernames are visible.  
 
# Usage: ./allUsersByDate2.sh
 
# Usage: ./allUsersByDate2.sh
  
Line 30: Line 31:
 
     echo
 
     echo
 
done
 
done
 
  
 
</pre></code>
 
</pre></code>

Revision as of 07:48, 28 September 2010

--D. Thiebaut 12:47, 28 September 2010 (UTC)


allUsersByDate2.sh

#! /bin/bash
# allUsersByDate2.sh
# Julia Burch
# September 22, 2010
# Like the first script, this one outputs all the users in the /Users
# directory by date of their last access. This time, only usernames are visible. 
# Usage: ./allUsersByDate2.sh

for year in "2005" "2006" "2007" "2008" "2009" "2010\|:"  
do
    if [ "$year" = "2010\|:" ]; then
	echo "2010"
    else
	echo $year
    fi
    ls -l /Users | grep $year > results.txt
    cat results.txt | 
    while read line
    do 
	IFS=" " 
	arr=($line)
	if [ ${arr[8]} != "lost+found" ]; then
	    echo ${arr[8]}
	fi
     done
    echo
done


allUsersByDate.sh

#! /bin/bash
# allUsersByDate.sh
# Julia Burch
# September 22, 2010
# This script lists all users on grendel by year of last access to their account.
# Usage: ./allUsersByDate.sh

for year in "2005" "2006" "2007" "2008" "2009" "2010\|:"  
do 
    if [ "$year" = "2010\|:" ]; then
	echo "2010"
    else
	echo $year
    fi
    ls -l /Users | grep $year
    echo
done


biggestVar2.sh

#! /bin/bash
# biggestVar.sh
# Julia Burch
# September 22, 2010
# This script prints the 10 largest directories in /var.
# ./biggestVar.sh

du -h /var 2>&1 | sort -h | tail -10


biggestVar.sh

#! /bin/bash
# biggestVar.sh
# Julia Burch
# September 22, 2010
# This script prints the 10 largest directories in /var.
# ./biggestVar.sh

du /var 2>&1 | sort -n | tail -10


lab1answers.sh

#! /bin/bash
# lab1answers
# Julia Burch
# September 22, 2010
# Answers to lab 1 exercises
# ./lab1answers.sh

echo "Path-Related Section: Question 1"
echo
pwd
echo

echo "Path-Related Section: Question 2"
echo
ls ..
echo

echo "Path-Related Section: Question 3"
echo
ls /home
echo

echo "Questions About File-Searching: Question 1"
echo
cat /etc/printcap | grep "ford"
echo

echo "Filtering Log Files: Question 1"
echo
wget  http://maven.smith.edu/~hadoop/log.txt
wc -l log.txt
echo

echo "Filtering Log Files: Question 2"
echo
grep "real" log.txt | sort -r
echo

echo "Filtering Log Files: Question 3"
echo
grep "real\|processing" log.txt  
echo

echo "Pipes: Question 1"
echo
ls /Users | wc -l
echo

echo "Pipes: Question 2"
echo
ls -ltr /Users | tail -3
echo

echo "Pipes: Question 3"
echo
ls -lt /Users | tail -3
echo

echo "Pipes: Question 4"
echo 
ls -l /Users | grep "Sep 22"
echo

echo "More challenging pipes: Question 1"
echo
cd /Users/classes/220a/bin
./stdouterr.py 2>&1 | grep "Error"
echo

echo "More challenging pipes: Question 2"
echo
./stdouterr.py 2>&1 | wc -l
echo

echo "More challenging pipes: Question 3"
echo
./stdouterr.py 2>&1 | grep "Error" | wc -l