Skip to content

Commit e1fdb7e

Browse files
Let's parse Apache logs
1 parent 2f44a6f commit e1fdb7e

14 files changed

+133
-0
lines changed
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDHojO4bcLLoBHHqixvz62qYnARgXJV7FOLMrRGAPbQG5+J2J3sgYKdvJBpefZPuX1nDUiYAr/tsDZqtUBiOeoyN53UynsRjFq7yzeNP83YDGVlSAmpXItXyU/pnt8Dh3rsn2XB9ftxoLIfoC/bd14V6/88YOVCpGvSjq9Ar8Wqlcw8flMbdrfgm/k0iJx3QBENegHoPfjl3bLTXvbt7WbxSHfLu7k4Vbo6Q2Ho13b6j59WCnJashs5xkJIl2/knorDQBAQzw62HQTUGJoWnN9XT6HZXRr6nrmwahjW3UikTZmIX5Raa6oGsWd/mYAXhyz+61ctUG5PCMrvI4C0H6zd9NrgfaJvdZudf2vmALryosPtfuY4La3Iv5iLq+u2wPWrLxsSRwHydOXWFUWPENH+ykCFqIthkIXrxFeulqdCSODdCTYqasXhVih8fCYrTjyVzaLhIwbOLSeVVwfqyrwdlCdLPC1RO9t40A8XCjzLkC3n3V0NVvsWIXWGbfC5WPk= root@0dbb6a60a695

Diff for: 0x04-loops_conditions_and_parsing/1-for_best_school

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
# This script is displaying "Best SChool" ten times
3+
for ((i=0; i<10; i++ ))
4+
do
5+
echo "Best School";
6+
done

Diff for: 0x04-loops_conditions_and_parsing/10-fizzbuzz

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
# printing fizz buzz algorithm
3+
i=1
4+
while ((i<=100));
5+
do
6+
if ((i%3==0 && i%5==0))
7+
then
8+
echo "FizzBuzz"
9+
elif ((i%3==0))
10+
then
11+
echo "Fizz"
12+
elif ((i%5==0))
13+
then
14+
echo "Buzz"
15+
else
16+
echo "$i"
17+
fi
18+
((i++))
19+
done

Diff for: 0x04-loops_conditions_and_parsing/100-read_and_cut

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
# print username, userid, home directory
3+
while read -r passwd; do
4+
echo "$passwd" | cut -d ':' -f1,3,6
5+
done < "/etc/passwd"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
# Parses Apache log files in list format.
3+
# Displays the IP and HTTP status code.
4+
5+
awk '{print $1 " " $9}' apache-access.log
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
# print "Best school"ten times with while loop
3+
i=0
4+
while [ $i -lt 10 ]
5+
do
6+
echo "Best School";
7+
((i++))
8+
done
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
# print "Best school"ten times with while loop
3+
i=0
4+
until [ $i -ge 10 ]
5+
do
6+
echo "Best School";
7+
((i++))
8+
done

Diff for: 0x04-loops_conditions_and_parsing/4-if_9_say_hi

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
# print "Best school"ten times with while loop
3+
i=0
4+
while [ $i -lt 10 ]
5+
do
6+
echo "Best School";
7+
if [ $i -eq 8 ]
8+
then
9+
echo "Hi";
10+
fi
11+
((i++))
12+
done
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
# conditionals and loop
3+
i=0
4+
while ((i<10));
5+
do
6+
if [ $i -eq 3 ]
7+
then
8+
echo "bad luck"
9+
elif [ $i -eq 7 ]
10+
then
11+
echo "good luck"
12+
else
13+
echo "Best School"
14+
fi
15+
((i++))
16+
done
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
# print fromone to 20 and some text
3+
i=1
4+
while [ $i -le 20 ]
5+
do
6+
echo "$i"
7+
case $i in
8+
4) echo "bad luck from China";;
9+
9) echo "bad luck from Japan";;
10+
17) echo "bad luck from Italy";;
11+
esac
12+
((i++))
13+
done

Diff for: 0x04-loops_conditions_and_parsing/7-clock

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env bash
2+
# printing Hours and minutes
3+
i=0
4+
while [ $i -le 12 ]
5+
do
6+
echo "Hour: $i"
7+
j=1
8+
while [ $j -le 59 ]
9+
do
10+
echo "$j"
11+
((j++))
12+
done
13+
((i++))
14+
done

Diff for: 0x04-loops_conditions_and_parsing/8-for_ls

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
# print the element in the working directory
3+
list=$(ls)
4+
for element in $list;
5+
do
6+
echo "$element" | cut -d '-' -f2
7+
done
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
# working with file
3+
if [ -e "school" ]
4+
then
5+
echo "school file exists"
6+
if [ -s "school" ]
7+
then
8+
echo "school file is not empty"
9+
else
10+
echo "school file is empty"
11+
fi
12+
if [ -f "school" ]
13+
then
14+
echo "school is a regular file"
15+
fi
16+
else
17+
echo "school file does not exist"
18+
fi

Diff for: 0x04-loops_conditions_and_parsing/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Exploring Bash Scripting if, until, while, for loop and others

0 commit comments

Comments
 (0)