Difference between revisions of "IT2DT2 Linux"
From Teknologisk videncenter
Computerkim (talk | contribs) (→Winning) |
m (→Winning) |
||
Line 81: | Line 81: | ||
=Winning= | =Winning= | ||
+ | <source lang=cli> | ||
#!/bin/bash | #!/bin/bash | ||
read -p "Path to log file: " file | read -p "Path to log file: " file | ||
Line 114: | Line 115: | ||
esac | esac | ||
done | done | ||
+ | </source> | ||
=Batman= | =Batman= |
Revision as of 09:47, 18 September 2011
Contents
Logfil opgave
Kopier apache httpd-access.log til et arbejdesbibliotek på din Linuxserver. Filen fylder ca 470 MB og er opsamlet i perioden 27 februar 2011 til 8. august 2011 fra mars.tekkom.dk.
- Find de 10 mest anvendte sider fra logfilen
- Find hvor mange eksterne sider der hentes
- Hvilke 10 sider er de mest populære eksternt
- Find hvor mange interne sider der hentes (RFC1918 adresser)
- Hvilke 10 sider er de mest populære internt
Konkurence
Der konkurerres om
- Det hold der først finder oplysningerne
- Det hold hvis script hurtigst finder informationerne
Hints
At komme igang
- Opret et arbejdsbibliotek
- Gå ind i det
- Hent den store logfil
- Lav en lille logfil med de øverste 10000 linier
heth@mars2:~$ <input>mkdir logfil</input>
heth@mars2:~$ <input>cd logfil</input>
heth@mars2:logfil$ <input>wget http://mars.tekkom.dk/data/httpd-access.log</input>
--2011-09-01 09:38:20-- http://mars.tekkom.dk/data/httpd-access.log
Læser mars.tekkom.dk... 127.0.1.1
Connecting to mars.tekkom.dk|127.0.1.1|:80... forbundet.
HTTP forespørgsel sendt, afventer svar... 200 OK
Længde: 468007853 (446M) [text/plain]
Saving to: `httpd-access.log'
100%[======================================>] 468.007.853 254M/s in 1,8s
2011-09-01 09:38:22 (254 MB/s) - `httpd-access.log' saved [468007853/468007853]
heth@mars2:logfil$ <input>head -n 10000 httpd-access.log > small.log</input>
1337 Team
- Kenneth H. Mørch.
- Kasper Ovesen.
- Henrik Pedersen
- Danny Christensen
#!/bin/sh
input=$1
output=$2
clear
echo "Sorting Logfile"
clear
echo "Sorting Logfile."
cat ${input} | awk '{ print $7}'|sort > ./apax.tmp &
cat ${input} | awk '{ print $1}'|sort > ./apax2.tmp &
echo "pre"
wait %1 %2
echo "post"
cat ./apax.tmp ./apax2.tmp > ./apa.tmp
clear
echo "Sorting Logfile.."
awk '{ print $1, $2}' ./apa.tmp | grep -E "index.php/|index.htm" | uniq -c | sort -nr > ./apache1337.tmp
clear
echo "Sorting Logfile..."
awk '{ print $1}' ./apa.tmp | grep -E "192.168.|172.16.|10.10." > ./apa.uni
awk '{ print $1, $2}' ./apa.uni | uniq -c | sort -nr > ./apache1337.uni
clear
echo "Sorting Logfile......"
echo -e "\n Writing output to a file..\n"
cat ./apache1337.tmp | head -n 10 > "${output}visits.Total"
cat ./apache1337.uni | head -n 10 > "${output}Internal.Total"
rm -R ./apache1337.tmp ./apache1337.uni
clear
echo "Done"
clear
exit 0
BRMS
BOGO
Winning
#!/bin/bash
read -p "Path to log file: " file
while true; do
clear
echo
echo 1 - Top iper
echo 2 - Top lokale iper
echo 3 - Top externe iper
echo 4 - Top sider
echo 5 - Top lokale sider
echo 6 - Top eksterne sider
echo 7 - Antal sider hentet
echo 8 - Antal sider hentet lokalt
echo 9 - Antal sider hentet eksternt
echo q/e - Exit
echo
echo Note: Use Q to exit the menues.
echo
read -p "Option: " key
case $key in
[1] ) clear; cat $file|cut -d ' ' -f 1|sort|uniq -c|sort -n -r|less;;
[2] ) clear; cat $file|cut -d ' ' -f 1|sort|grep -e '^10.\|^192.168.\|^172.16.\|^172.17.\|^172.18.\|^172.19.\|^172.20.\|^172.21.\|^172.22.\|^172.23.\|^172.24.\|^172.25.\|^172.26.\|^172.27.\|^172.28.\|^172.29.\|^172.30.\|^172.31.'|sort|uniq -c|sort -n -r|less;;
[3] ) clear; cat $file|cut -d ' ' -f 1|sort|grep -v -e '^10.\|^192.168.\|^172.16.\|^172.17.\|^172.18.\|^172.19.\|^172.20.\|^172.21.\|^172.22.\|^172.23.\|^172.24.\|^172.25.\|^172.26.\|^172.27.\|^172.28.\|^172.29.\|^172.30.\|^172.31.'|sort|uniq -c|sort -n -r|less;;
[4] ) clear; cat $file|cut -d ' ' -f 7|sort|grep 'index.php'|sort|uniq -c|sort -n -r|less;;
[5] ) clear; cat $file|grep -e '^10.\|^192.168.\|^172.16.\|^172.17.\|^172.18.\|^172.19.\|^172.20.\|^172.21.\|^172.22.\|^172.23.\|^172.24.\|^172.25.\|^172.26.\|^172.27.\|^172.28.\|^172.29.\|^172.30.\|^172.31.'|sort|grep 'index.php'|sort|cut -d ' ' -f 7|sort|grep 'index.php'|sort|uniq -c|sort -n -r|less;;
[6] ) clear; cat $file|grep -v -e '^10.\|^192.168.\|^172.16.\|^172.17.\|^172.18.\|^172.19.\|^172.20.\|^172.21.\|^172.22.\|^172.23.\|^172.24.\|^172.25.\|^172.26.\|^172.27.\|^172.28.\|^172.29.\|^172.30.\|^172.31.'|sort|grep 'index.php'|sort|cut -d ' ' -f 7|sort|grep 'index.php'|sort|uniq -c|sort -n -r|less;;
[7] ) clear; echo Antal sider hentet: $(cat $file|wc -l);read;;
[8] ) clear; echo Antal sider hentet lokalt: $(cat $file|grep -e '^10.\|^192.168.\|^172.16.\|^172.17.\|^172.18.\|^172.19.\|^172.20.\|^172.21.\|^172.22.\|^172.23.\|^172.24.\|^172.25.\|^172.26.\|^172.27.\|^172.28.\|^172.29.\|^172.30.\|^172.31.'|sort|grep 'index.php'|sort|wc -l);read;;
[9] ) clear; echo Antal sider hentet eksternt: $(cat $file|grep -v -e '^10.\|^192.168.\|^172.16.\|^172.17.\|^172.18.\|^172.19.\|^172.20.\|^172.21.\|^172.22.\|^172.23.\|^172.24.\|^172.25.\|^172.26.\|^172.27.\|^172.28.\|^172.29.\|^172.30.\|^172.31.'|sort|grep 'index.php'|sort|wc -l);read;;
[EeQq]* ) clear; break;;
* ) clear; echo Error: Invalid option!;;
esac
done