aktuelle.kurse/m122/bash6AufgUndLoesg/BashUebungsaugaben1und2_Loes.tex

272 lines
6.6 KiB
TeX
Raw Normal View History

2021-08-30 15:20:49 +02:00
\documentclass[a4paper,11pt]{report}
%\usepackage{isolatin1}
%\usepackage{german}
\usepackage{float}
\usepackage{listings}
\usepackage{graphicx}
\usepackage{lastpage}
\usepackage{fancyhdr}
\usepackage{soul}
\usepackage{lmodern} % Latin Modern
\usepackage[ngerman]{babel, translator}
\usepackage[utf8]{inputenc}
%\usepackage[ngerman]{babel, translator}
%\usepackage[utf8x]{inputenc}
\usepackage[left=2.5cm,top=2cm,right=2cm,bottom=4cm]{geometry}
%Code listings
\usepackage{listings}
\usepackage{etoolbox}
\patchcmd{\chapter}{\thispagestyle{plain}}{\thispagestyle{fancy}}{}{}
\usepackage[]{hyperref}
\hypersetup{
linkcolor=blue,
pagecolor= blue,
urlcolor= blue,
colorlinks=true,
pdfborder=0 0 0
}
\usepackage[
nonumberlist, %keine Seitenzahlen anzeigen
acronym, %ein Abk�rzungsverzeichnis erstellen
toc, %Eintr�ge im Inhaltsverzeichnis
section] %im Inhaltsverzeichnis auf section-Ebene erscheinen
{glossaries}
\usepackage{hyperref}
%Ein eigenes Symbolverzeichnis erstellen
\newglossary[slg]{symbolslist}{syi}{syg}{Symbolverzeichnis}
%Den Punkt am Ende jeder Beschreibung deaktivieren
\renewcommand*{\glspostdescription}{}
%Glossar-Befehle anschalten
\makeglossaries
%Diese Befehle sortieren die Eintr�ge in den
%einzelnen Listen:
%makeindex -s datei.ist -t datei.alg -o datei.acr datei.acn
%makeindex -s datei.ist -t datei.glg -o datei.gls datei.glo
%makeindex -s datei.ist -t datei.slg -o datei.syi datei.syg
% define acronyms here
\newacronym{PDF}{PDF}{Portable Document Format}
\newacronym{APDU}{APDU}{Application Protocol Data Unit}
\newacronym{AGPL}{AGPL}{Affero General Public License}
\newacronym{GPL}{GPL}{General Public License}
\newacronym{LGPL}{LGPL}{Lesser General Public License}
\newacronym{DCT}{DCT}{Discrete Cosine Transform}
\newacronym{TTA}{TTA}{Trusted Timestamp Authority}
\newacronym{OCSP}{OCSP}{Online Certificate Status Protocol}
\newacronym{PKI}{PKI}{Public Key Infrastructure}
%\newacronym{BDD}{BDD}{Behaviour Driven Development\protect\glsadd{glos:BDD}}
\newglossaryentry{Application Protocol Data Unit}
{
name={Application Protocol Data Unit},
description={blablabla}
}
\newglossaryentry{Copyleft}
{
name={Copyleft},
description={The copyleft ist the obligation required by the GLP (or AGPL) license to offer the source code of a work (and every derivative of it) to the public (open source). Copy{\bf{left}} can also be considered as the opposite of copy{\bf{right}}. }
}
%Befehle f�r Glossar
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\renewcommand\contentsname{Inhaltsverzeichnis}
%Einstellungen f??r code listings
\lstset{inputencoding=utf8, language=Java,tabsize=2, basicstyle=\small,breaklines=true,showstringspaces=false}
\pagestyle{fancy}
\setlength{\headheight}{38pt}
\setlength{\headwidth}{470pt}
\renewcommand{\headrule}{\hskip -\leftskip{\bf \quad \quad}\vbox to 5pt{\hbox to 455pt{\hrulefill}}}
\renewcommand{\footrule}{\hskip-\leftskip{\bf \quad \quad}{\hbox to 450 pt{\hrulefill}\newline}}
\fancyhf{}
\fancyheadoffset[L]{1cm}
\fancyfootoffset[L]{1cm}
%Kopfzeile links bzw. innen
\fancyhead[L]{\includegraphics[height=0.6in]{img/bfsulogo.jpg}}
%Kopfzeile mittig
\fancyhead[C]{}
%Kopfzeile rechts bzw. au??????????�?en
\fancyhead[R]{\hspace{10pt} Modul 122\\Abläufe mit Skripts/Makros automatisieren\\ \rightmark }
\fancyheadoffset[L]{1cm}
\fancyfootoffset[L]{1cm}
%Linie oben
\renewcommand{\headrulewidth}{0.7pt}
%Fu??????????�?zeile mittig
\cfoot{\vspace*{6mm}page:\ \thepage\ of \pageref{LastPage}}
\fancyfoot[R]{}
% footnote in footer
\newcommand{\fancyfootnotetext}[2]{%
\fancypagestyle{dingens}{%
\fancyfoot[LO,RE]{\parbox{12cm}{\footnotemark[#1]\footnotesize #2}}%
}%
\thispagestyle{dingens}%
}
%Linie unten
\renewcommand{\footrulewidth}{0.5pt}
\vspace*{15mm}
\textwidth 450pt
\begin{document}
\setcounter{tocdepth}{5}
%\thispagestyle{empty}
\begin{center}
\vspace{48pt}
\vspace{15pt}
\begin{huge}
\end{huge}
\vspace{10pt}
\begin{center}
\begin{Large}
Linux Bash \\ \vspace{20pt}
Beispiellösungen Übungsaufgaben 1 \& 2
\end{Large}
\end{center}
\vspace{10pt}
\end{center}
\begin{scriptsize}
\begin{center}
\noindent Mario Bischof
\end{center}
\end{scriptsize}
\newpage
\begin{quote}
{\bf{Aufgabe 1.1:}}\\\\
Der Dateiname, welcher die Benutzernamen beinhaltet, wird mit \verb|$1| übergeben.
\begin{verbatim}
#!/bin/bash
for user in $(cat $1); do useradd $user; done
\end{verbatim}
{\bf{Aufgabe 1.2:}}\\\\
Der Dateiname, welcher die Gruppen beinhaltet, wird it \verb|$1| übergeben, der Benutzernamen mit \verb|$2|.
\begin{verbatim}
#!/bin/bash
for group in $(cat $1); do groupadd $group $2; done
\end{verbatim}
{\bf{Aufgabe 1.3:}}\\\\
Der Benutzername wird mit \verb|$1| übergeben
\begin{verbatim}
#!/bin/bash
name=$1_$(date '+%y-%m-%d').tar.gz;
find / -user $1 -exec cp {} /root/found/ \;
tar -zcvf "/root/found/$name" /root/found/;
find /root/found/ -type f ! -name "$name" -delete;
\end{verbatim}
{\bf{Aufgabe 1.4:}}\\\\
Das tool \verb|fping| muss installiert sein (\verb|apt-get install fping|).
\begin{verbatim}
#!/bin/bash
for i in $( ifconfig | grep "inet Adr" | grep -v "127.0.0.1" |
cut -d ":" -f 2 | cut -d "." -f 1-3 ); do
for k in $(seq 1 255); do
fping -c 1 -t250 $i.$k 2>&1 | grep " 0% " | cut -d " " -f 1 >> ips.txt
done
done
# alternative Lösung:
fping -g -c 1 -t250 172.16.6.0/24 2>&1 | grep " 0% " | cut -d " " -f 1 > ips.txt
\end{verbatim}
{\bf{Aufgabe 1.5:}}\\\\
Bonusfrage
\newpage
{\bf{Aufgabe 2.1:}}
\begin{verbatim}
[root@host: ] mkdir /root/trash
[root@host: ] touch /root/trash/file{1..10}
[root@host: ] nano /root/trash.sh
#!/bin/bash
rm /root/trash/*
[root@host: ] chmod +x trash.sh
[root@host: ] crontab -e
*/5 * * * * /root/trash.sh
[root@host: ] watch ls /root/trash
(Warten bis files verschwinden --> erfolgreiche Ausführung)
\end{verbatim}
{\bf{Aufgabe 2.2:}}\\\\
IP wird als \verb|$1| übergeben, \emph{ban} oder \emph{unban} als \verb|$2|.
\begin{verbatim}
#!/bin/bash
if [ $2 = "ban" ]
then
echo "banning " $1
iptables -A INPUT -s $1 -j DROP
elif [ $2 = "unban" ]
then
echo "unbanning " $1
iptables -D INPUT -s $1 DROP
else
echo "Verwendung:"
echo "1.Arg: IP-Adresse"
echo "2.Arg.: ban oder unban"
echo "Beispiel: ./ban.sh 192.168.13.3 ban"
fi
\end{verbatim}
{\bf{Aufgabe 2.4:}}\\\\
Setzen des SGID Bits (3 verschiedene Varianten):
\begin{verbatim}
[root@host: ] chmod g+s /data/myFile
[root@host: ] chmod +s /data/myFile
[root@host: ] chmod 2755 /data/myFile
\end{verbatim}
Setzen des Sticky Bits (3 verschiedene Varianten):
\begin{verbatim}
[root@host: ] chmod o+t /data
[root@host: ] chmod +t /data
[root@host: ] chmod 1755 /data
\end{verbatim}
\end{quote}
\end{document}