Listings added and Section 4 revised
This commit is contained in:
@@ -12,4 +12,11 @@
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
*.log
|
||||
*.aux
|
||||
*.gz
|
||||
*.out
|
||||
*.tmp
|
||||
*.old
|
||||
*.new
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
\indexentry{declare|hyperpage}{1}
|
||||
Binary file not shown.
@@ -66,6 +66,7 @@
|
||||
\input{Kapitel2/Index}
|
||||
\input{Kapitel3/Index}
|
||||
\input{Kapitel4/Index}
|
||||
\input{Kapitel5/Index}
|
||||
|
||||
\backmatter
|
||||
\include{Anhang}
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
\babel@toc {ngerman}{}\relax
|
||||
\contentsline {chapter}{Vorwort}{v}{chapter*.3}%
|
||||
\contentsline {chapter}{\numberline {1}Allgemein}{1}{chapter.1}%
|
||||
\contentsline {section}{\numberline {1.1}Variablen}{1}{section.1.1}%
|
||||
\contentsline {subsection}{\numberline {1.1.1}Definition}{1}{subsection.1.1.1}%
|
||||
\contentsline {subsection}{\numberline {1.1.2}Variablen l\"ange}{2}{subsection.1.1.2}%
|
||||
\contentsline {subsection}{\numberline {1.1.3}Variablen default}{2}{subsection.1.1.3}%
|
||||
\contentsline {subsection}{\numberline {1.1.4}Variablen Warnung}{3}{subsection.1.1.4}%
|
||||
\contentsline {subsection}{\numberline {1.1.5}Array}{4}{subsection.1.1.5}%
|
||||
\contentsline {subsection}{\numberline {1.1.6}Gro\ss - / Kleinbuchstaben}{5}{subsection.1.1.6}%
|
||||
\contentsline {subsection}{\numberline {1.1.7}String-Operationen}{6}{subsection.1.1.7}%
|
||||
\contentsline {section}{\numberline {1.2}Datum in Bash Scripte}{7}{section.1.2}%
|
||||
\contentsline {section}{\numberline {1.3}Ein- und Ausgabe auf der Shell}{9}{section.1.3}%
|
||||
\contentsline {subsection}{\numberline {1.3.1}Echo}{9}{subsection.1.3.1}%
|
||||
\contentsline {subsection}{\numberline {1.3.2}Read}{9}{subsection.1.3.2}%
|
||||
\contentsline {subsection}{\numberline {1.3.3}Printf}{9}{subsection.1.3.3}%
|
||||
\contentsline {subsection}{\numberline {1.3.4}Null}{11}{subsection.1.3.4}%
|
||||
\contentsline {subsection}{\numberline {1.3.5}Beispiele}{12}{subsection.1.3.5}%
|
||||
\contentsline {section}{\numberline {1.4}Set-Befehl im Bash Script}{13}{section.1.4}%
|
||||
\contentsline {section}{\numberline {1.5}Programm Parameter auswerten}{15}{section.1.5}%
|
||||
\contentsline {section}{\numberline {1.6}Shell Script Testen}{15}{section.1.6}%
|
||||
\contentsline {section}{\numberline {1.7}Tabs setzten}{16}{section.1.7}%
|
||||
\contentsline {section}{\numberline {1.8}Befehle mehrzeilig}{16}{section.1.8}%
|
||||
\contentsline {section}{\numberline {1.9}Befehle verketten}{16}{section.1.9}%
|
||||
\contentsline {section}{\numberline {1.10}XARGS}{17}{section.1.10}%
|
||||
\contentsline {section}{\numberline {1.11}Signale (Traps)}{18}{section.1.11}%
|
||||
\contentsline {section}{\numberline {1.12}Exec}{21}{section.1.12}%
|
||||
\contentsline {subsection}{\numberline {1.12.1}Ein-/Ausgabekanal}{21}{subsection.1.12.1}%
|
||||
\contentsline {chapter}{\numberline {2}Schleifen / Bedingungen}{23}{chapter.2}%
|
||||
\contentsline {section}{\numberline {2.1}Vergleichsparameter}{23}{section.2.1}%
|
||||
\contentsline {section}{\numberline {2.2}Case Anweisung}{24}{section.2.2}%
|
||||
\contentsline {section}{\numberline {2.3}If Anweisung}{24}{section.2.3}%
|
||||
\contentsline {subsection}{\numberline {2.3.1}Allgemein}{24}{subsection.2.3.1}%
|
||||
\contentsline {subsection}{\numberline {2.3.2}Beispiele}{25}{subsection.2.3.2}%
|
||||
\contentsline {subsection}{\numberline {2.3.3}Beispiele Vergleichen}{26}{subsection.2.3.3}%
|
||||
\contentsline {section}{\numberline {2.4}While / Until Schleife}{27}{section.2.4}%
|
||||
\contentsline {section}{\numberline {2.5}For Schleife}{28}{section.2.5}%
|
||||
\contentsline {section}{\numberline {2.6}Functions}{30}{section.2.6}%
|
||||
\contentsline {chapter}{\numberline {3}GUI}{31}{chapter.3}%
|
||||
\contentsline {section}{\numberline {3.1}Yad}{31}{section.3.1}%
|
||||
\contentsline {subsection}{\numberline {3.1.1}Allgemein}{31}{subsection.3.1.1}%
|
||||
\contentsline {subsection}{\numberline {3.1.2}Beispiele}{33}{subsection.3.1.2}%
|
||||
\contentsline {subsubsection}{\numberline {3.1.2.1}Formulare}{33}{subsubsection.3.1.2.1}%
|
||||
\contentsline {subsubsection}{\numberline {3.1.2.2}Passwortabfrage}{34}{subsubsection.3.1.2.2}%
|
||||
\contentsline {subsubsection}{\numberline {3.1.2.3}Zahlenabfrage}{35}{subsubsection.3.1.2.3}%
|
||||
\contentsline {subsubsection}{\numberline {3.1.2.4}Menüdialog Panel}{36}{subsubsection.3.1.2.4}%
|
||||
\contentsline {subsubsection}{\numberline {3.1.2.5}Entscheidungabfrage}{37}{subsubsection.3.1.2.5}%
|
||||
\contentsline {subsubsection}{\numberline {3.1.2.6}Systeminfo}{38}{subsubsection.3.1.2.6}%
|
||||
\contentsline {section}{\numberline {3.2}Dialog}{40}{section.3.2}%
|
||||
\contentsline {subsection}{\numberline {3.2.1}buildlist}{41}{subsection.3.2.1}%
|
||||
\contentsline {subsection}{\numberline {3.2.2}Calendar}{41}{subsection.3.2.2}%
|
||||
\contentsline {subsection}{\numberline {3.2.3}Checklist}{42}{subsection.3.2.3}%
|
||||
\contentsline {subsection}{\numberline {3.2.4}dselect}{42}{subsection.3.2.4}%
|
||||
\contentsline {subsection}{\numberline {3.2.5}editbox}{43}{subsection.3.2.5}%
|
||||
\contentsline {subsection}{\numberline {3.2.6}Form}{44}{subsection.3.2.6}%
|
||||
\contentsline {subsection}{\numberline {3.2.7}Fselect}{44}{subsection.3.2.7}%
|
||||
\contentsline {subsection}{\numberline {3.2.8}Gauge}{44}{subsection.3.2.8}%
|
||||
\contentsline {subsection}{\numberline {3.2.9}Infobox}{45}{subsection.3.2.9}%
|
||||
\contentsline {subsection}{\numberline {3.2.10}Inputbox}{45}{subsection.3.2.10}%
|
||||
\contentsline {subsection}{\numberline {3.2.11}Inputmenu}{46}{subsection.3.2.11}%
|
||||
\contentsline {subsection}{\numberline {3.2.12}Menu}{46}{subsection.3.2.12}%
|
||||
\contentsline {subsection}{\numberline {3.2.13}Mixedform}{47}{subsection.3.2.13}%
|
||||
\contentsline {subsection}{\numberline {3.2.14}Mixedgauge}{47}{subsection.3.2.14}%
|
||||
\contentsline {subsection}{\numberline {3.2.15}Msgbox}{47}{subsection.3.2.15}%
|
||||
\contentsline {subsection}{\numberline {3.2.16}Passwordbox}{48}{subsection.3.2.16}%
|
||||
\contentsline {subsection}{\numberline {3.2.17}Passwordform}{48}{subsection.3.2.17}%
|
||||
\contentsline {subsection}{\numberline {3.2.18}Pause}{48}{subsection.3.2.18}%
|
||||
\contentsline {subsection}{\numberline {3.2.19}Prgbox}{49}{subsection.3.2.19}%
|
||||
\contentsline {subsection}{\numberline {3.2.20}Programbox}{49}{subsection.3.2.20}%
|
||||
\contentsline {subsection}{\numberline {3.2.21}Progressbox}{49}{subsection.3.2.21}%
|
||||
\contentsline {subsection}{\numberline {3.2.22}Radiolist}{50}{subsection.3.2.22}%
|
||||
\contentsline {subsection}{\numberline {3.2.23}Rangebox}{50}{subsection.3.2.23}%
|
||||
\contentsline {subsection}{\numberline {3.2.24}Tailbox}{50}{subsection.3.2.24}%
|
||||
\contentsline {subsection}{\numberline {3.2.25}Tailboxbg}{51}{subsection.3.2.25}%
|
||||
\contentsline {subsection}{\numberline {3.2.26}Textbox}{51}{subsection.3.2.26}%
|
||||
\contentsline {subsection}{\numberline {3.2.27}Timebox}{51}{subsection.3.2.27}%
|
||||
\contentsline {subsection}{\numberline {3.2.28}Treeview}{51}{subsection.3.2.28}%
|
||||
\contentsline {subsection}{\numberline {3.2.29}YesNo}{51}{subsection.3.2.29}%
|
||||
\contentsline {chapter}{\numberline {4}Beispiele}{53}{chapter.4}%
|
||||
\contentsline {section}{\numberline {4.1}Backup Script}{53}{section.4.1}%
|
||||
\contentsline {section}{\numberline {4.2}Benutzereingabe}{55}{section.4.2}%
|
||||
\contentsline {section}{\numberline {4.3}Teilstring}{57}{section.4.3}%
|
||||
\contentsline {section}{\numberline {4.4}Eval}{58}{section.4.4}%
|
||||
\contentsline {section}{\numberline {4.5}Auswahlmenu mit Select}{59}{section.4.5}%
|
||||
\contentsline {section}{\numberline {4.6}Datei zur Laufzeit erstellen}{61}{section.4.6}%
|
||||
\contentsline {section}{\numberline {4.7}Scriptoptionen}{62}{section.4.7}%
|
||||
\contentsline {section}{\numberline {4.8}Ausgabe Version}{64}{section.4.8}%
|
||||
\contentsline {section}{\numberline {4.9}Ausgabe Datei Name}{64}{section.4.9}%
|
||||
\contentsline {section}{\numberline {4.10}Ausgabe Datei Pfad}{64}{section.4.10}%
|
||||
\contentsline {section}{\numberline {4.11}Let}{65}{section.4.11}%
|
||||
\contentsline {section}{\numberline {4.12}Network}{65}{section.4.12}%
|
||||
\contentsline {subsection}{\numberline {4.12.1}Up / Down}{65}{subsection.4.12.1}%
|
||||
\contentsline {section}{\numberline {4.13}Generate MAC-Adresse / UUID}{66}{section.4.13}%
|
||||
\contentsline {section}{\numberline {4.14}Datei einlesen}{67}{section.4.14}%
|
||||
\contentsline {section}{\numberline {4.15}Datei als Tabelle ausgeben}{69}{section.4.15}%
|
||||
\contentsline {section}{\numberline {4.16}Datei schreiben}{71}{section.4.16}%
|
||||
\contentsline {section}{\numberline {4.17}Generate Password}{71}{section.4.17}%
|
||||
\contentsline {section}{\numberline {4.18}List Files}{71}{section.4.18}%
|
||||
\contentsline {section}{\numberline {4.19}Erase Files}{71}{section.4.19}%
|
||||
\contentsline {section}{\numberline {4.20}Check Root}{72}{section.4.20}%
|
||||
\contentsline {section}{\numberline {4.21}String Encode \& Decode}{73}{section.4.21}%
|
||||
\contentsline {chapter}{\numberline {5}Testen}{75}{chapter.5}%
|
||||
\contentsline {section}{\numberline {5.1}Syntaxprüfung}{75}{section.5.1}%
|
||||
\contentsline {section}{\numberline {5.2}Testumfang}{75}{section.5.2}%
|
||||
\contentsline {section}{\numberline {5.3}Verwendung von echo}{75}{section.5.3}%
|
||||
\contentsline {section}{\numberline {5.4}Bash-Optionen}{75}{section.5.4}%
|
||||
\contentsline {section}{\numberline {5.5}Verwendung von PS4}{76}{section.5.5}%
|
||||
@@ -1,20 +1,23 @@
|
||||
\section{Ausgabe Datei Name}
|
||||
\begin{flushleft}
|
||||
Die Ausgabe des Script Namens wird mit {\ttfamily basename \$0} gemacht.
|
||||
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoBasename.sh, label=lst:bash]
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoBasename.sh]
|
||||
uws@tux>cat DemoBasename.sh
|
||||
#!/bin/env bash
|
||||
#!/usr/bin/env bash
|
||||
echo Script Name: $(basename $0)
|
||||
\end{lstlisting}
|
||||
|
||||
echo Script Name: $(basename $0 .sh)
|
||||
|
||||
uws@tux>./DemoBasename.sh
|
||||
Script Name: DemoBasename.sh
|
||||
Script Name: DemoBasename
|
||||
\end{lstlisting}
|
||||
M"ochte man aus einer Pfadangabe nur den Dateiname haben, so wird hierzu nur
|
||||
{\ttfamily basename} mit dem Pfad aufgerufen. Soll auch die Extension abgeschnitten
|
||||
werden, so wird nach der Angabe der Datei noch die Extension geschrieben.
|
||||
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoBasename1.sh, label=lst:bash]
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoBasename1.sh]
|
||||
uws@tux>basename /daten/script/MyScript.py
|
||||
MyScript.py
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
\section{Ausgabe Datei Pfad}
|
||||
\begin{flushleft}
|
||||
Die Ausgabe des Script Pfades kann man mit oder ohne den Namen des Scripts ermitteln.
|
||||
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoScriptPath.sh]
|
||||
uws@tux>cat DemoScriptPath.sh
|
||||
|
||||
@@ -5,23 +5,23 @@ Mit einem {\ttfamily select} in einem Script kann man ein Auswahlmenu darstellen
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoSelect.sh]
|
||||
uws@tux>cat DemoSelect.sh
|
||||
#!/bin/env bash
|
||||
declare -A WERT # Array deklarieren
|
||||
WERT["Montag Backup"]="backup.Mo.sh"
|
||||
WERT["Dienstag Backup"]="backupDi.sh"
|
||||
WERT["Mittwoch Backup"]="backupMi.sh"
|
||||
#!/usr/bin/env bash
|
||||
declare -A Wert # Array deklarieren
|
||||
Wert["Montag Backup"]="backupMo.sh"
|
||||
Wert["Dienstag Backup"]="backupDi.sh"
|
||||
Wert["Mittwoch Backup"]="backupMi.sh"
|
||||
|
||||
printf "\n\tBitte Backup ausw"ahlen: \n\n"
|
||||
#
|
||||
# Das Ausrufezeichen vor der Array Variable gibt die Array Index No.
|
||||
# aus und das @ Zeichen zwischen den [] gibt dann alle Index No. aus.
|
||||
#
|
||||
select Backup in "${!WERT[@]}";
|
||||
select Backup in "${!Wert[@]}";
|
||||
do
|
||||
BACKUPSCRIPT=${WERT[${BACKUP}]}
|
||||
TITLE="${BACKUP}"
|
||||
printf "\n\tDas ${TITLE} mit dem Script ${BACKUPSCRIPT} wird ausgefuehrt.\n\n"
|
||||
~/bin/${BACKUPSCRIPT}
|
||||
BackupScript=${WERT[${Bckup}]}
|
||||
TITLE="${Backup}"
|
||||
printf "\n\tDas ${TITLE} mit dem Script ${BackupScript} wird ausgefuehrt.\n\n"
|
||||
~/bin/${BackupScript}
|
||||
exit 0
|
||||
done
|
||||
|
||||
@@ -42,27 +42,29 @@ Hier ist noch ein weiteres Beispiel f"ur eine {\ttfamily select} Anweisung.
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoSelect1.sh]
|
||||
uws@tux>cat DemoSelect1.sh
|
||||
#!/bin/env bash
|
||||
WDR2="http://www.wdr2.de"
|
||||
SPORT="http://www.sportschau.de"
|
||||
#!/usr/bin/env bash
|
||||
Wdr2="http://www.wdr2.de"
|
||||
Sport="http://www.sportschau.de"
|
||||
|
||||
printf "\n\tBitte Web Seite auswaehlen: \n\n"
|
||||
select A in WDR2\ Seite Sportschau\ Seite;
|
||||
select A in WDR2\ Seite Sportschau\ Seite; # \ maskiert ein Leerzeichen
|
||||
do
|
||||
case $A in
|
||||
WDR*)
|
||||
printf "\n\tFolgende URL wird aufgerufen: ${WDR2}.\n\n"
|
||||
firefox ${WDR2}
|
||||
exit 0
|
||||
;;
|
||||
SPORT*)
|
||||
printf "\n\tFolgende URL wird aufgerufen: ${SPORT}.\n\n"
|
||||
firefox ${SPORT}
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
case $A in
|
||||
WDR*)
|
||||
printf "\n\tFolgende URL wird aufgerufen: ${Wdr2}.\n\n"
|
||||
firefox ${Wdr2}
|
||||
exit 0
|
||||
;;
|
||||
Sport*)
|
||||
printf "\n\tFolgende URL wird aufgerufen: ${Sport}.\n\n"
|
||||
firefox ${Sport}
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
\end{lstlisting}
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=Aufruf DemoSelect1.sh]
|
||||
uws@tux>./DemoSelect1.sh
|
||||
|
||||
Bitte Web Seite auswaehlen:
|
||||
@@ -74,5 +76,4 @@ uws@tux>./DemoSelect1.sh
|
||||
Folgende URL wird aufgerufen: http://www.wdr2.de.
|
||||
|
||||
\end{lstlisting}
|
||||
|
||||
\end{flushleft}
|
||||
|
||||
+30
-13
@@ -1,48 +1,65 @@
|
||||
\section{Backup Script}
|
||||
\begin{flushleft}
|
||||
Mit diesem Script wird ein Backup von einem Verzeichnis ersteelt und die Sicherungsarchive
|
||||
Mit diesem Script wird ein Backup von einem Verzeichnis erstellt und die Sicherungsarchive
|
||||
werden hochgez"ahlt. Ist das Sicherungsverzeichnis nicht vorhanden, so wird es angelegt.
|
||||
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=Backup.sh, label=lst:bash]
|
||||
uws@tux>cat backup.sh
|
||||
#!/bin/env bash
|
||||
#!/usr/bin/env bash
|
||||
#==========================================================================
|
||||
# FILE: backup.sh
|
||||
#
|
||||
# Seab@er Software - Backup Script
|
||||
# USAGE: backup.sh
|
||||
#
|
||||
# DESCRIPTION: Backup with timestamp
|
||||
#
|
||||
# OPTIONS:
|
||||
# REQUIREMENTS:
|
||||
# BUGS: ---
|
||||
# NOTES:
|
||||
# AUTHOR: Uwe Schimanski
|
||||
# COMPANY:
|
||||
# MAIL: uschimanski@seabaer-net.eu
|
||||
# COPYRIGHT: © 2025 Uwe Schimanski
|
||||
# VERSION: 25.10.03
|
||||
# CREATED: 03.10.2025
|
||||
# REVISION:
|
||||
#==========================================================================
|
||||
BACKUPDIR=/daten/backup
|
||||
SOURCEDIR=/daten/bilder
|
||||
TIMESTAMP=backup-timestamp.dat
|
||||
|
||||
# Backup Verzeichnis vorhanden?
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Backup Verzeichnis vorhanden?
|
||||
#--------------------------------------------------------------------------
|
||||
if [ ! -d "${BACKUPDIR}" ]; then
|
||||
echo "Das Verzeichnis ${BACKUPDIR} ist nicht vorhanden"
|
||||
echo "und wird nun angelegt! "
|
||||
mkdir -p ${BACKUPDIR}
|
||||
fi
|
||||
|
||||
set -- ${BACKUPDIR}/backup-???.tgz # Alle Backups einlesen in $1, $2 usw.
|
||||
lastname=${!#} # Letzter Backup Name
|
||||
backupnr=${lastname##*backup-} # Pfad und backup- entfernen
|
||||
backupnr=${backupnr%%.*} # Alles hinter dem ersten "." Entfernen
|
||||
backupnr=${backupnr//\?/0} # Keine Backups vorhanden, dann 0
|
||||
backupnr=${backupnr//\?/0} # Keine Backups vorhanden, dann 0
|
||||
backupnr=$[10#${backupnr}] # Fuehrende Nullen entfernen, (siehe in
|
||||
# der Bash-Manpage unter base#)
|
||||
|
||||
if [ "$[backupnr++]" -ge 999]; then # Erhoehen des Wertes um 1
|
||||
|
||||
if [ "$[backupnr++]" -ge 999]; then # Erhoehen des Wertes um 1
|
||||
echo "Error: Schon 999 Backups vorhanden! "
|
||||
exit 1
|
||||
exit 1
|
||||
fi
|
||||
|
||||
backupnr=000${backupnr} # Nullen voranstellen
|
||||
backupnr=${backupnr: -3} # Die letzten 3 Ziffern herausschneiden,
|
||||
# das Leerzeichen vor dem - ist noetig.
|
||||
filename=backup-${backupnr}.tgz
|
||||
echo "Sichere veraenderte Daten in ${filename}."
|
||||
|
||||
# Es erfolgt ein inkrementelles Backup, Schalter -g
|
||||
|
||||
#--------------------------------------------------------------------------
|
||||
# Es erfolgt ein inkrementelles Backup, Schalter -g
|
||||
#--------------------------------------------------------------------------
|
||||
tar -czf ${BACKUPDIR}/${filename} -g ${BACKUPDIR}/$ {TIMESTAMP} ${SOURCEDIR}
|
||||
\end{lstlisting}
|
||||
|
||||
\end{flushleft}
|
||||
|
||||
@@ -1,13 +1,21 @@
|
||||
\section{Benutzereingabe}
|
||||
\begin{justify}
|
||||
M"ochte man den Benutzer eine Eingabe erm"oglichen, so wird hierzu der Befehl {\ttfamily read} verwendet. Werden mehr Worte als definierte Variablen eingegeben, so bekommt die letzte Variablen den Rest des Textes. Werden weniger Worte eingegeben, so bleiben die letzten Variablen leer.
|
||||
M"ochte man den Benutzer eine Eingabe erm"oglichen, so wird hierzu der Befehl {\ttfamily read} verwendet. Werden mehr Werte als definierte Variablen eingegeben, so bekommt die letzte Variablen den Rest des Textes. Werden weniger Werte eingegeben, so bleiben die letzten Variablen leer.
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoRead.sh, label=lst:bash]
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoRead.sh]
|
||||
uws@tux>cat DemoRead.sh
|
||||
#!/bin/env bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
printf "\nBitte Werte eingeben: \n"
|
||||
read str1 str2 str3 str4
|
||||
|
||||
printf "\nFolgende Werte wurden eingegeben: $str1 $str2 $str3 $str4\n"
|
||||
|
||||
uws@tux>./DemoRead.sh
|
||||
Bitte Werte eingeben:
|
||||
Hans Paul Nina Karl Walter
|
||||
|
||||
Folgende Werte wurden eingegeben: Hans Paul Nina Karl Walter
|
||||
\end{lstlisting}
|
||||
F"ur {\ttfamily read} gibt es folgende Optionen:
|
||||
\begin{table}[ht]
|
||||
@@ -30,15 +38,27 @@ Wenn nach {\ttfamily read} keine Variable angegeben wird, so kann man den eingeg
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoReadReply, label=lst:bash]
|
||||
uws@tux>cat DemoReadReply.sh
|
||||
#!/bin/env bash
|
||||
#!/usr/bin/env bash
|
||||
# Default Value for read is reply
|
||||
printf "\nWas ist deine Lieblingsfarbe? \n"
|
||||
read
|
||||
printf "\nDeine Lieblingsfarbe ist: $REPLY\n"
|
||||
printf "\nWas ist dein Lieblingsverein? \n"
|
||||
read VEREIN
|
||||
printf "\nDein Lieblingsverein ist: $VEREIN\n"
|
||||
read Verein
|
||||
printf "\nDein Lieblingsverein ist: $Verein\n"
|
||||
printf "und deine Lieblingsfarbe ist: $REPLY\n"
|
||||
exit 0
|
||||
|
||||
uws@tux>./DemoreadReply.sh
|
||||
Was ist deine Lieblingsfarbe?
|
||||
Blau
|
||||
|
||||
Deine Lieblingsfarbe ist: Blau
|
||||
|
||||
Was ist dein Lieblingsverein?
|
||||
FC Goch
|
||||
|
||||
Dein Lieblingsverein ist: FC Goch
|
||||
und deine Lieblinngsfarbe ist: Blau
|
||||
\end{lstlisting}
|
||||
\end{justify}
|
||||
|
||||
+19
-10
@@ -4,17 +4,26 @@ Soll das Script der User {\ttfamily root} ausführen und man möchte Überprüfe
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=CheckRoot.sh]
|
||||
@uws@tux>cat CheckRoot.sh
|
||||
#!/bin/env bash
|
||||
#!/usr/bin/env bash
|
||||
function CheckRootID() {
|
||||
ROOT_ID=$(id -u $USER)
|
||||
printf "Root ID: $ROOT_ID\n"
|
||||
ROOT_ID=$(id -u $USER)
|
||||
printf "Root ID: $ROOT_ID\n"
|
||||
|
||||
if [ "$ROOT_ID" == "0" ]
|
||||
then
|
||||
printf "Root User found.\n"
|
||||
else
|
||||
printf "This script run only under root account!\n"
|
||||
exit 1
|
||||
fi
|
||||
if [ "$ROOT_ID" == "0" ]
|
||||
then
|
||||
printf "Root User found.\n"
|
||||
else
|
||||
printf "This script run only under root account!\n"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
CheckRootID
|
||||
|
||||
uws@tux>./CheckRoot.sh
|
||||
Root ID: 1000
|
||||
This script run only under root account!
|
||||
|
||||
uws@tux>sudo ./CheckRoot.sh
|
||||
Root ID: 0
|
||||
Root User found.
|
||||
\end{lstlisting}
|
||||
|
||||
+70
-40
@@ -4,7 +4,7 @@
|
||||
Eine Datei kann man mit {\ttfamily IFS} und {\ttfamily read} einlesen. Die Datei wird direkt in Variablen gespeichert.
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=Read Datei]
|
||||
uws@tux>cat DemoRead.sh
|
||||
uws@tux>cat DemoReadFile.sh
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Einlesen der Datei mit dem Feldtrenner :
|
||||
@@ -52,52 +52,82 @@ Letzte Zeile
|
||||
\end{lstlisting}
|
||||
\newpage
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoReadFile.sh]
|
||||
uws@tux>cat daten.xt
|
||||
Das ist Zeile 1.
|
||||
Das ist Zeile 2.
|
||||
Das ist Zeile 3.
|
||||
Das ist Zeile 4.
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoReadFile1.sh]
|
||||
uws@tux>cat daten.xt
|
||||
Das ist Zeile 1.
|
||||
Das ist Zeile 2.
|
||||
Das ist Zeile 3.
|
||||
Das ist Zeile 4.
|
||||
|
||||
uws@tux>cat DemoReadFile.sh
|
||||
#!/bin/env bash
|
||||
while read line
|
||||
do
|
||||
echo -e "$line \n"
|
||||
done < daten.txt
|
||||
uws@tux>cat DemoReadFile1.sh
|
||||
#!/usr/bin/env bash
|
||||
while read line
|
||||
do
|
||||
echo -e "$line \n"
|
||||
done < daten.txt
|
||||
|
||||
uws@tux>./DemoReadFile1.sh
|
||||
Das ist Zeile 1.
|
||||
|
||||
Das ist Zeile 2.
|
||||
|
||||
Das ist Zeile 3.
|
||||
|
||||
Das ist Zeile 4.
|
||||
\end{lstlisting}
|
||||
Eine Datei einlesen, in der die Daten durch einen Separator getrennt sind.
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoReadFileSeparator.sh]
|
||||
uws@tux>cat DemoReadFileSeparator.sh
|
||||
#!/bin/env bash
|
||||
while IFS=':' read user pass uid gid full home shell
|
||||
do
|
||||
echo -e "$full:\n\
|
||||
PSEUDO: $user\n\
|
||||
UID : $uid\n\
|
||||
GID : $gid\n\
|
||||
HOME : $home\n\
|
||||
Shell : $shell\n\n"
|
||||
done < /etc/passwd
|
||||
\end{lstlisting}
|
||||
Die Kommentar Zeilen einer Datei nicht auswerten. In dem nachfolgenden Beispiel werden sie extra ausgegeben.
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoReadFileComments.sh]
|
||||
uws@tux>cat DemoReadFileComments.sh
|
||||
!#/bin/env bash
|
||||
i=1
|
||||
while IFS=';' SOURCE BACKUP
|
||||
do
|
||||
if [ "${SOURCE:0:1}" != "#" ]; then
|
||||
printf "\tQuell Path: $SOURCE\n"
|
||||
printf "\tBackup Path: $BACKUP\n\n"
|
||||
else
|
||||
printf "\tComment $((i++)); $SOURCE\n\n"
|
||||
fi
|
||||
done <$1
|
||||
uws@tux>cat DemoReadFileSeparator.sh
|
||||
#!/bin/env bash
|
||||
while IFS=':' read user pass uid gid full home shell
|
||||
do
|
||||
echo -e "$full:\n\
|
||||
PSEUDO: $user\n\
|
||||
UID : $uid\n\
|
||||
GID : $gid\n\
|
||||
HOME : $home\n\
|
||||
Shell : $shell\n\n"
|
||||
done < /etc/passwd
|
||||
|
||||
uws@tux>./DemoReadFileSeparator
|
||||
:
|
||||
PSEUDO: root
|
||||
UID : 0
|
||||
GID : 0
|
||||
HOME : /root
|
||||
Shell : /bin/bash
|
||||
|
||||
|
||||
Nobody:
|
||||
PSEUDO: nobody
|
||||
UID : 65534
|
||||
GID : 65534
|
||||
HOME : /
|
||||
Shell : /usr/bin/nologin
|
||||
\end{lstlisting}
|
||||
%\newpage
|
||||
\begin{justify}
|
||||
% ---- Script funktioniert nicht
|
||||
% ----
|
||||
%Die Kommentar Zeilen einer Datei nicht auswerten. In dem nachfolgenden Beispiel werden sie extra ausgegeben.
|
||||
%\listBash
|
||||
%\begin{lstlisting}[captionpos=b, caption=DemoReadFileComments.sh]
|
||||
%uws@tux>cat DemoReadFileComments.sh
|
||||
%!#/bin/env bash
|
||||
%i=1
|
||||
%while IFS=';' SOURCE BACKUP
|
||||
%do
|
||||
% if [ "${SOURCE:0:1}" != "#" ]; then
|
||||
% printf "\tQuell Path: $SOURCE\n"
|
||||
% printf "\tBackup Path: $BACKUP\n\n"
|
||||
% else
|
||||
% printf "\tComment $((i++)); $SOURCE\n\n"
|
||||
% fi
|
||||
%done <$1
|
||||
%\end{lstlisting}
|
||||
Eine Variable kann folgenderma\ss{}en eine Datei einlesen.
|
||||
\end{justify}
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=VariableRead]
|
||||
uws@tux>export VALUE=`cat pd.dat`
|
||||
|
||||
@@ -5,27 +5,34 @@ kann jede Zeichenfolge verwendet werden, meistens wird {\ttfamily EOF} als Trenn
|
||||
zwischen den Trenner steht, wird in eine neue Datei ausgegeben.
|
||||
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoCreateFile.sh, label=lst:bash]
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoCreateFile.sh]
|
||||
uws@tux>cat DemoCreateFile.sh
|
||||
#!/bin/env bash
|
||||
cat <<EOF > "NewScript"
|
||||
#!/bin/env bash
|
||||
#!/usr/bin/env bash
|
||||
cat <<EOF > "NewScript.sh"
|
||||
#!/usr/bin/env bash
|
||||
# Laufzeiterstelltes Script
|
||||
#
|
||||
printf "\n\tHier geht es los!\n"
|
||||
ls -lash
|
||||
EOF
|
||||
|
||||
uws@tuc>cat NewScript.sh
|
||||
#!/usr/bin/env bash
|
||||
# Laufzeiterstelltes Script
|
||||
#
|
||||
printf "\n\tHier geht es los!\n"
|
||||
ls -lash
|
||||
\end{lstlisting}
|
||||
|
||||
Wird in einem Script Taps verwendet, so muss ein {\ttfamily -} Zeichen vor dem Trenner gesetzt werden.
|
||||
Dann werden die Taps ignoriert.
|
||||
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoCreateFileTaps.sh, label=lst:bash]
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoCreateFileTaps.sh]
|
||||
uws@tux>cat DemoCreateFileTaps.sh
|
||||
#!/bin/env bash
|
||||
cat <<-EOF > "NewScriptTaps"
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
cat <<-EOF > "NewScriptTaps.sh"
|
||||
#!/usr/bin/bash
|
||||
# Laufzeiterstelltes Script mit Taps
|
||||
#
|
||||
if test -r /home/uws/bin/test.txt
|
||||
@@ -34,6 +41,15 @@ then
|
||||
ls -lash
|
||||
fi
|
||||
EOF
|
||||
\end{lstlisting}
|
||||
|
||||
us@tux>cat NewScriptTaps.sh
|
||||
#!/usr/bin/bash
|
||||
# Laufzeiterstelltes Script mit Taps
|
||||
#
|
||||
if test -r /home/uws/bin/test.txt
|
||||
then
|
||||
printf "\n\tHier geht es los!\n"
|
||||
ls -lash
|
||||
fi
|
||||
\end{lstlisting}
|
||||
\end{flushleft}
|
||||
|
||||
+10
-13
@@ -3,9 +3,9 @@
|
||||
Mit {\ttfamily Eval} is es m"oglich, Kommandos auszuf"uhren, als w"urden sie in der Shell ausgef"uhrt.
|
||||
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=Commands.sh, label=lst:bash]
|
||||
\begin{lstlisting}[captionpos=b, caption=Commands.sh]
|
||||
uws@tux>cat commands.sh
|
||||
#!/bin/env bash
|
||||
#!/usr/bin/env bash
|
||||
while true
|
||||
do
|
||||
printf "\tCommand: "
|
||||
@@ -13,7 +13,7 @@ do
|
||||
eval $REPLY
|
||||
done
|
||||
|
||||
uws@tux>./commands.txt
|
||||
uws@tux>./commands.sh
|
||||
Command: ls *.sh
|
||||
commands.sh DemoEval.sh
|
||||
Comand: echo $$
|
||||
@@ -27,9 +27,9 @@ Es besteht die M"oglichkeit, indirekt auf eine Variable zugreifen zu k"onnen. In
|
||||
Beispiel wird dieses gemacht.
|
||||
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoEval.sh, label=lst:bash]
|
||||
uws@tux>cat commands.sh
|
||||
#!/bin/env bash
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoEval.sh]
|
||||
uws@tux>cat DemoEval.sh
|
||||
#!/usr/bin/env bash
|
||||
Mo=backupMo
|
||||
Di=backupDi
|
||||
Mi=backupMi
|
||||
@@ -38,8 +38,8 @@ Fr=backupFr
|
||||
Sa=backupSa
|
||||
So=backupSo
|
||||
|
||||
tag=`date +"%a"`
|
||||
eval backup=$$tag
|
||||
tag=$(date +%a)
|
||||
eval backup=\$$tag
|
||||
printf "\n\tDas Backup Script $backup wird ausgefuehrt.\n\n"
|
||||
./$backup
|
||||
|
||||
@@ -47,10 +47,7 @@ uws@tux>./DemoEval.sh
|
||||
|
||||
Das Backup Script: backupDi wird ausgefuehrt.
|
||||
./backupDi
|
||||
|
||||
\end{lstlisting}
|
||||
|
||||
Im ersten Durchlauf wird aus {\ttfamily \$\$tag => \$Di}. Die Variable {\ttfamily \$Di} hat den Vert {\ttfamily backupDi}
|
||||
und dieses wird im zweiten Durchlauf der Variable {\ttfamily backup} zugewiesen.
|
||||
|
||||
Im ersten Durchlauf wird aus {\ttfamily \verb|\|\$\$tag => \$Di}. Die Variable {\ttfamily \$Di} hat den Wert {\ttfamily backupDi}
|
||||
und dieses wird im zweiten Durchlauf der Variable {\ttfamily backup} zugewiesen. Das erste Dollrzeichen wurde im ersten Durchlauf mit einem Backslash maskiert und somit vor einem Zugriff der Shell geschützt. Dadurch blieb im zweiten Durchlauf nur noch das Dollarzeichen übrig.
|
||||
\end{flushleft}
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
\section{Let}
|
||||
\begin{flushleft}
|
||||
Mit {\ttfamily let} kann man Berechnungen durchf"uhren.
|
||||
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoLet.sh, label=lst:bash]
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoLet.sh]
|
||||
uws@tux>let "m=4*1024" && echo -e "\tErgebnis: $m"
|
||||
Ergebnis: 4096
|
||||
|
||||
@uws@tux>cat DemoLet.sh
|
||||
#!/bin/env bash
|
||||
#!/usr/bin/env bash
|
||||
let wert1=20
|
||||
let wert2=10
|
||||
|
||||
let m=$wert1+$wert2 && echo -e "Ergebnis: $m"
|
||||
uws@tux>bash DemoGerade.sh
|
||||
|
||||
Wert von Day: 326
|
||||
Wert von MDAY: 0
|
||||
uws@tux>bash DemoLet.sh
|
||||
|
||||
Ergebnis: 30
|
||||
\end{lstlisting}
|
||||
\end{flushleft}
|
||||
|
||||
@@ -2,18 +2,18 @@
|
||||
\subsection{Up / Down}
|
||||
\begin{flushleft}
|
||||
Ein einfacher Netzwerktest, ob das Netz vorhanden ist..
|
||||
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoNetwork.sh, label=lst:bash]
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoNetwork.sh]
|
||||
uws@tux>bash DemoNetwork.sh
|
||||
#!/bin/env bash
|
||||
HOST_NAME=\$1
|
||||
#!/usr/bin/env bash
|
||||
HostName=$1
|
||||
|
||||
printf "Warte auf das Netz"
|
||||
printf "Warte auf das Netz\n"
|
||||
|
||||
while [ $(ping -w1 -c1 $HOST_NAME | grep -c "0 received") -eq 1 ]; do
|
||||
while [ $(ping -w1 -c1 $HostName | grep -c "0 received") -eq 1 ]; do
|
||||
printf "."
|
||||
done
|
||||
|
||||
printf "\nNetz ist up.\n"
|
||||
\end{lstlisting}
|
||||
\end{flushleft}
|
||||
|
||||
+57
-47
@@ -1,68 +1,78 @@
|
||||
\section{Scriptoptionen}
|
||||
\begin{flushleft}
|
||||
M"ochte man in einem Script Optionen / Parameter "ubergeben und auswerten, so geschieht
|
||||
das mit {\ttfamily getopts}. Alle Optionen / Parameter k"onnen in beliebiger Reihenfolge gesetzt werden.
|
||||
Erfolgt nach einer Option / Parameter ein {\ttfamily Doppelpunkt}, wie im unteren Beispiel nach dem
|
||||
{\ttfamily f}, so wird f"ur diese Option / Parameter ein Wert ben"otigt.
|
||||
M"ochte man in einem Script Optionen/Parameter "ubergeben und auswerten, so geschieht
|
||||
das mit {\ttfamily getopts}. Alle Optionen/Parameter k"onnen in beliebiger Reihenfolge gesetzt werden.
|
||||
Erfolgt nach einer Option/Parameter ein {\ttfamily Doppelpunkt}, wie im unteren Beispiel nach dem
|
||||
{\ttfamily f}, so wird f"ur diese Option/Parameter ein Wert ben"otigt. Der Vorteil bei der Verwendung von {\ttfamily getopts} ist, das man sich nicht darum kümmern muss, ob der zweite Parameter angegeben worden ist.
|
||||
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoOption.sh, label=lst:bash]
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoOption.sh]
|
||||
uws@tux>cat DemoOption.sh
|
||||
#!/bin/env bash
|
||||
while getops "abf:hv" Arg; do
|
||||
#!/usr/bin/env bash
|
||||
while getopts "abf:hv" Arg; do
|
||||
case ${Arg} in
|
||||
a) printf "Die Option -a wurde "ubergeben.";;
|
||||
b) printf "Die Option -b wurde "ubergeben.";;
|
||||
a) printf "Die Option -a wurde uebergeben.\n";;
|
||||
b) printf "Die Option -b wurde uebergeben.\n";;
|
||||
f) if [ -f ${OPTARG} ]; then
|
||||
filename=${OPTARG}
|
||||
fi
|
||||
;;
|
||||
h) printf "Die Syntax lautet: ...";;
|
||||
h) printf "Die Syntax lautet: ...\n";;
|
||||
v) verbose=y;;
|
||||
esac
|
||||
done
|
||||
|
||||
uws@tux>./DemoOption.sh -a
|
||||
Die Option -a wurde uebergeben.
|
||||
|
||||
uws@tux>./DemoOption.sh -f
|
||||
DemoOption.sh: Diese Option erfordert ein Argument -- f
|
||||
\end{lstlisting}
|
||||
|
||||
Script Optionen / Parameter k"onnen auch mit einer Kombination von {\ttfamily while} und
|
||||
{\ttfamily case} ausgewertet werden.
|
||||
|
||||
Script Optionen/Parameter k"onnen auch mit einer Kombination von {\ttfamily while} und
|
||||
{\ttfamily case} ausgewertet werden. Hierbei muss man sich selbst darum kümmern, ob ein zweiter benötigter Wert angegeben wurde. In dem nachfolgenden Beispiel die Option o.
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoOptionWithCase.sh, label=lst:bash]
|
||||
uws@tux>cat DemoDemoOptionWithCase.sh
|
||||
#!/bin/env bash
|
||||
VERBOSE="0"
|
||||
OUTFILE=""
|
||||
\begin{lstlisting}[captionpos=b, caption=DemoOptionWithCase.sh]
|
||||
uws@tux>cat DemoOptionWithCase.sh
|
||||
#!/usr/bin/env bash
|
||||
|
||||
Verbos="0"
|
||||
OutFile=""
|
||||
|
||||
while [ $# -gt 0 ]
|
||||
do
|
||||
case $1 in
|
||||
-h|--help)
|
||||
printf "\n"
|
||||
printf "Folgende Optionen sind zulaessig:\n"
|
||||
printf "-h|--help : Diese Hilfe\n"
|
||||
printf "-v|--verbose : Statusinformatione n\n"
|
||||
printf "-o|--outfile <file> : Ausgabe in <file>\ n\n"
|
||||
exit 0
|
||||
;;
|
||||
-v|--verbose)
|
||||
VERBOSE="1"
|
||||
;;
|
||||
-o|--outfile)
|
||||
shift # Parameter $2 wird $1
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
printf "Error: No File Name\n" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
OUTFILE="$1"
|
||||
;;
|
||||
*)
|
||||
printf "Unbekannte Option: $1\n" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
\end{lstlisting}
|
||||
-h|--help)
|
||||
HelpTxt="""
|
||||
-h|--help : Diese Hilfe
|
||||
-v|--verbose : Statusinformationen
|
||||
-o|--outfile <file> : Ausgabe in <file>
|
||||
"""
|
||||
|
||||
printf "\nFolgende Optionen sind zulaessig:\n"
|
||||
printf "${HelpTxt}\n\n"
|
||||
exit 0
|
||||
;;
|
||||
-v|--verbose)
|
||||
Verbose="1"
|
||||
;;
|
||||
-o|--outfile)
|
||||
shift # Parameter $2 wird $1
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
printf "Error: No File Name\n" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
OutFile="$1"
|
||||
;;
|
||||
*)
|
||||
printf "Unbekannte Option: $1\n" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
uws@tux>./DemoOptionWithCase.sh -o
|
||||
Error: No File Name
|
||||
\end{lstlisting}
|
||||
\end{flushleft}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
Einen String Ver- und Entschlüsseln wird in diesem Beispiel mit {\ttfamily openssl} gemacht. Das ganze wurde in einer Funktion erstellt, kann aber auch als alleiniges Script gemacht werden.
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=Function scrypt]
|
||||
#!/usr/bin/env bash
|
||||
#==========================================================================
|
||||
# Function: scrypt
|
||||
#==========================================================================
|
||||
@@ -24,9 +25,9 @@ do
|
||||
printf "${COLOR_GREEN}Syntax:${RESET}\n"
|
||||
printf " $(basename $0) [-h|--help] [-e] [-d]\n\n"
|
||||
printf "${COLOR_GREEN}-e:${RESET}\n"
|
||||
printf " Verschlüsseln eines Strings.\n\n"
|
||||
printf " Verschluesseln eines Strings.\n\n"
|
||||
printf "${COLOR_GREEN}-d:${RESET}\n"
|
||||
printf " Entschlüsslen eines Secrets.\n\n"
|
||||
printf " Entschluesslen eines Secrets.\n\n"
|
||||
;;
|
||||
-v|--version)
|
||||
printf "$(basename $0) ${Version}\n"
|
||||
@@ -53,4 +54,23 @@ do
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
scrypt $1
|
||||
\end{lstlisting}
|
||||
Nun rufen wir das Programm auf.
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=Function aufruf]
|
||||
uws@tux>./FunctionScrypt -h
|
||||
|
||||
Syntax:
|
||||
FunctionScrypt.sh [-h|--help] [-e] [-d]
|
||||
|
||||
-e:
|
||||
Verschluesseln eines Strings.
|
||||
|
||||
-d:
|
||||
Entschluesslen eines Secrets.
|
||||
|
||||
uws@tux>./FunctionScrypt -e "GeheimesPassword"
|
||||
Secret: U2FsdGVkX1/XLkfVQAosj6ZiqbtnPVti
|
||||
\end{lstlisting}
|
||||
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
\chapter{Testen}
|
||||
%-------------------------------------------
|
||||
% load other documents
|
||||
%------------------------------------------
|
||||
\input{Kapitel5/Testing}
|
||||
@@ -0,0 +1,120 @@
|
||||
%-------------------------------------------------------------------------------
|
||||
% Section: Syntaxprüfung
|
||||
%-------------------------------------------------------------------------------
|
||||
\section{Syntaxprüfung}
|
||||
\begin{justify}
|
||||
Um eine Syntaxprüfung für das Bash Script zu machen, so wird der Parameter {\bfseries -n} verwendet. Die Befehle werden gelesen, aber nicht ausgeführt. Es werden nur grobe Fehler gefunden. Schreibfehler wie z.B. cho statt echo wird nicht beanstattet, da cho eine Funktion oder auch der Name eines Programms sein kann.
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=Syntaxprüfung]
|
||||
uws@tux>bash -n demo.sh
|
||||
\end{lstlisting}
|
||||
%-------------------------------------------------------------------------------
|
||||
% Section: Testumfang
|
||||
%-------------------------------------------------------------------------------
|
||||
\section{Testumfang}
|
||||
In einer Testumgbung werden Beispieldateien oder Beispieldaten für die Entwicklungsphase benötigt. Das vermindert die Gefahr, unbeabsichtigt Veränderungen an wichtige Dateien vorzunehmen.
|
||||
%-------------------------------------------------------------------------------
|
||||
% Section: Verwendung von echo
|
||||
%-------------------------------------------------------------------------------
|
||||
\section{Verwendung von echo}
|
||||
Werden in dem Script z.B. Dateien gelöscht, so ist es besser für die Testläufe das {\bfseries rm} durch ein {\bfseries echo} zu ersetzen. So kann man sehen, welche Dateien gelöscht werden sollen.
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=Echo]
|
||||
for Datei in *.sh
|
||||
do
|
||||
#rm "${Datei}"
|
||||
echo "rm \"${Datei}\"" # Nach erfolgreicher Pruefung entfernen
|
||||
done
|
||||
\end{lstlisting}
|
||||
%-------------------------------------------------------------------------------
|
||||
% Section: Bash-Optionen
|
||||
%-------------------------------------------------------------------------------
|
||||
\section{Bash-Optionen}
|
||||
\begin{longtable}[l]{p{1.5cm}p{2.5cm}p{12cm}}
|
||||
\rowcolor{hellgrau}\multicolumn{1}{l}{\textbf{Option}} & \multicolumn{1}{l}{\textbf{set -o Option}} & \multicolumn {1}{l}{\textbf{Beschreibung}} \\
|
||||
\hline
|
||||
\hline
|
||||
\endfirsthead
|
||||
%\multicolumn{2}{c}{{\bfseries \tablename \thetable{} continued from previous page.}} \\
|
||||
\multicolumn{2}{r}{{\bfseries continued from previous page.}} \\
|
||||
\rowcolor{hellgrau}\multicolumn{1}{l}{\textbf{Option}} & \multicolumn{1}{l}{\textbf{set -o Option}} & \multicolumn {1}{l}{\textbf{Beschreibung}} \\
|
||||
\hline
|
||||
\hline
|
||||
\endhead
|
||||
%\multicolumn{2}{r}{{\bfseries \tablename \thetable{} Continued on next page}} \\
|
||||
\multicolumn{2}{r}{{\bfseries Continued on next page}} \\
|
||||
\endfoot
|
||||
\caption{Bash-Optionen} \\
|
||||
\endlastfoot
|
||||
-n & noexec & Befehle werden nicht ausgeführt, nur Syntaxprüfung erfolgt \\
|
||||
-v & verbose & Gibt die Zeilen eines Scripts vor der Ausführung aus \\
|
||||
-x & xtrace & Gibt die Zeilen eines Scripts nach der Ersetzungen aus \\
|
||||
\end{longtable}
|
||||
\newpage
|
||||
\begin{justify}
|
||||
Folgendes Beispiel veranschaulicht es.
|
||||
\end{justify}
|
||||
\begin{lstlisting}[captionpos=b, caption=Beispiel]
|
||||
uws@tux>cat demo.sh
|
||||
#!/usr/bin/env bash
|
||||
|
||||
TempFile=$(mktemp /tmp/example.XXXXX) || exit 1
|
||||
echo "Programm output" >> ${TempFile}
|
||||
rm --force ${TempFile}
|
||||
|
||||
uws@tux>bash -xv ./demo.sh
|
||||
|
||||
TMPFILE=$( mktemp /tmp/example.XXXXXXXXXX ) || exit 1
|
||||
mktemp /tmp/example.XXXXXXXXXX
|
||||
++ mktemp /tmp/example.XXXXXXXXXX
|
||||
+ TMPFILE=/tmp/example.AVkuGd6796
|
||||
echo "program output" >> $TMPFILE
|
||||
+ echo ’program output’
|
||||
rm --force $TMPFILE
|
||||
+ rm --force /tmp/example.AVkuGd6796
|
||||
\end{lstlisting}
|
||||
Die {\bfseries -x Option} erzeugt ein {\bfseries +} Zeichen bei beginnenden Zeilen. Die Anzahl der Pluszeichen ergibt die Erstzungstiefe wieder. In dem Script kann man für einen Block auch die -x Option ein- und ausschalten.
|
||||
\begin{lstlisting}[captionpos=b, caption=Xtrace]
|
||||
set -o xtrace # --- xtrace ein ---
|
||||
for datei in *.sh
|
||||
do
|
||||
rm "$datei"
|
||||
done
|
||||
set +o xtrace # --- xtrace aus ---
|
||||
\end{lstlisting}
|
||||
%-------------------------------------------------------------------------------
|
||||
% Section: Verwendung von PS4
|
||||
%-------------------------------------------------------------------------------
|
||||
\section{Verwendung von PS4}
|
||||
Mit der Shell-Variable {\bfseries PS4} werden die Ausgabezeilen für die Option -x festgelegt. Der Voreingestellte Wert ist das + Zeichen. Nachfolgend sind drei Beispiele für PS4 angegeben.
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=PS4]
|
||||
# PS4 : position, line number, function name
|
||||
# The following line avoids error messages due to an unset FUNCNAME[0] :
|
||||
set +o nounset # Treat unset variables not as an error
|
||||
|
||||
PS4=’+|${BASH_SOURCE##*/} ${LINENO}${FUNCNAME[0]:+ ${FUNCNAME[0]}}| ’
|
||||
|
||||
#PS4 : timestamp; the current time in 24-hour HH:MM:SS format
|
||||
PS4=’+[\t] ’
|
||||
|
||||
#PS4 : timestamp; ’seconds.nanoseconds’ since 1970-01-01 00:00:00 UT
|
||||
PS4=’+[$(date "+%s.%N")] ’
|
||||
\end{lstlisting}
|
||||
\newpage
|
||||
\begin{justify}
|
||||
AusgabeZeilen unter Verwendung der ersten PS4 definition.
|
||||
\end{justify}
|
||||
\listBash
|
||||
\begin{lstlisting}[captionpos=b, caption=Ausgabe]
|
||||
+|test.sh 41| for n in ’{1..4}’
|
||||
+|test.sh 42| function1
|
||||
+|test.sh 30 function1| echo ’-- in function1 --’
|
||||
-- in function1 --
|
||||
+|test.sh 31 function1| function2
|
||||
+|test.sh 37 function2| echo ’-- in function2 --’
|
||||
-- in function2 --
|
||||
+|test.sh 32 function1| echo ’-- in function1 again --’
|
||||
-- in function1 again --
|
||||
\end{lstlisting}
|
||||
\end{justify}
|
||||
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
function CheckRootID() {
|
||||
ROOT_ID=$(id -u $USER)
|
||||
printf "Root ID: $ROOT_ID\n"
|
||||
|
||||
if [ "$ROOT_ID" == "0" ]
|
||||
then
|
||||
printf "Root User found.\n"
|
||||
else
|
||||
printf "This script run only under root account!\n"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
CheckRootID
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
echo Script Name: $(basename $0)
|
||||
|
||||
echo Script Name: $(basename $0 .sh)
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
cat <<EOF > "NewScript.sh"
|
||||
#!/bin/env bash
|
||||
# Laufzeiterstelltes Script
|
||||
#
|
||||
printf "\n\tHier geht es los!\n"
|
||||
ls -lash
|
||||
EOF
|
||||
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
cat <<-EOF > "NewScriptTaps.sh"
|
||||
#!/usr/bin/bash
|
||||
# Laufzeiterstelltes Script mit Taps
|
||||
#
|
||||
if test -r /home/uws/bin/test.txt
|
||||
then
|
||||
printf "\n\tHier geht es los!\n"
|
||||
ls -lash
|
||||
fi
|
||||
EOF
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
Mo=backupMO
|
||||
Di=backupDi
|
||||
Mi=backupMi
|
||||
Do=backupDo
|
||||
Fr=backupFr
|
||||
Sa=backupSa
|
||||
So=backupSo
|
||||
|
||||
tag=$(date +%a)
|
||||
echo $tag
|
||||
eval backup=\$$tag
|
||||
echo $tag
|
||||
echo $backup
|
||||
printf "\n\tDas Backup Script $backup wird ausgefuehrt.\n\n"
|
||||
./$backup
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
let wert1=20
|
||||
let wert2=10
|
||||
|
||||
let m=$wert1+$wert2 && echo -e "Ergebnis: $m"
|
||||
@@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
HostName=$1
|
||||
|
||||
printf "Warte auf das Netz\n"
|
||||
|
||||
while [ $(ping -w1 -c1 $HostName | grep -c "0 received") -eq 1 ]; do
|
||||
printf "."
|
||||
done
|
||||
|
||||
printf "\nNetz ist up.\n"
|
||||
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
while getopts "abf:hv" Arg; do
|
||||
case ${Arg} in
|
||||
a) printf "Die Option -a wurde uebergeben.\n";;
|
||||
b) printf "Die Option -b wurde uebergeben.\n";;
|
||||
f) if [ -f ${OPTARG} ]; then
|
||||
filename=${OPTARG}
|
||||
fi
|
||||
;;
|
||||
h) printf "Die Syntax lautet: ...\n";;
|
||||
v) verbose=y;;
|
||||
esac
|
||||
done
|
||||
@@ -0,0 +1,38 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
Verbos="0"
|
||||
OutFile=""
|
||||
|
||||
while [ $# -gt 0 ]
|
||||
do
|
||||
case $1 in
|
||||
-h|--help)
|
||||
HelpTxt="""
|
||||
-h|--help : Diese Hilfe
|
||||
-v|--verbose : Statusinformationen
|
||||
-o|--outfile <file> : Ausgabe in <file>
|
||||
"""
|
||||
printf "\n"
|
||||
printf "Folgende Optionen sind zulaessig:\n"
|
||||
printf "${HelpTxt}\n\n"
|
||||
exit 0
|
||||
;;
|
||||
-v|--verbose)
|
||||
Verbose="1"
|
||||
;;
|
||||
-o|--outfile)
|
||||
shift # Parameter $2 wird $1
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
printf "Error: No File Name\n" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
OutFile="$1"
|
||||
;;
|
||||
*)
|
||||
printf "Unbekannte Option: $1\n" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
printf "\nBitte Werte eingeben: \n"
|
||||
read str1 str2 str3 str4
|
||||
|
||||
printf "\nFolgende Werte wurden eingegeben: $str1 $str2 $str3 $str4\n"
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
##
|
||||
# Einlesen der Datei mit dem Feldtrenner :
|
||||
while IFS=: read BENUTZERNAME A B C D HOMEDIR E; do
|
||||
printf "$BENUTZERNAME -> $HOMEDIR\n"
|
||||
done < /etc/passwd
|
||||
|
||||
# Als Tabelle
|
||||
printf "|%23s | %-30s |\n" "Username" "Homedir"
|
||||
printf "+%23s + %-30s +\n" "-----------------------" "------------------------------"
|
||||
while IFS=: read BENUTZERNAME A B C D HOMEDIR E; do
|
||||
printf "|%23s | %-30s |\n" $BENUTZERNAME $HOMEDIR
|
||||
done < /etc/passwd
|
||||
printf "+%23s + %-30s +\n" "-----------------------" "------------------------------"
|
||||
|
||||
# Einlesen der Datei mit dem Feldtrenner Leerzeichen
|
||||
while IFS=" " read A1 A2; do
|
||||
printf "$A1 : $A2\n"
|
||||
done < liste.txt
|
||||
|
||||
# Return code Auswertung
|
||||
declare -a RESULT
|
||||
for SRV in $(cat server.lst)
|
||||
do
|
||||
ssh -x ${USER}@${SRV} 'ls' 2> /dev/null
|
||||
status=$?
|
||||
if [[ $status -gt 0 ]]
|
||||
then
|
||||
RESULT+=("$SRV")
|
||||
printf "Server: ${SRV}\n"
|
||||
else
|
||||
printf " Ok: ${SRV}\n"
|
||||
fi
|
||||
done
|
||||
|
||||
for i in ${!RESULT[*]}
|
||||
do
|
||||
printf "Not Ok: ${RESULT[$i]}\n"
|
||||
done
|
||||
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
while read line
|
||||
do
|
||||
echo -e "$line \n"
|
||||
done < daten.txt
|
||||
@@ -0,0 +1,10 @@
|
||||
#!/bin/env bash
|
||||
while IFS=':' read user pass uid gid full home shell
|
||||
do
|
||||
echo -e "$full:\n\
|
||||
PSEUDO: $user\n\
|
||||
UID : $uid\n\
|
||||
GID : $gid\n\
|
||||
HOME : $home\n\
|
||||
Shell : $shell\n\n"
|
||||
done < /etc/passwd
|
||||
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
# Default Value for read is reply
|
||||
printf "\nWas ist deine Lieblingsfarbe? \n"
|
||||
read
|
||||
printf "\nDeine Lieblingsfarbe ist: $REPLY\n"
|
||||
printf "\nWas ist dein Lieblingsverein?\n"
|
||||
read Verein
|
||||
printf "\nDein Lieblingsverein ist: $Verein\n"
|
||||
printf "und deine Lieblinngsfarbe ist: $REPLY\n"
|
||||
exit 0
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
printf "Script Pfad without Name: $(dirname $(realpath "$0"))\n"
|
||||
printf " Script Pfad with Name: $(realpath "$0")\n"
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
declare -A Wert # Array deklarieren
|
||||
Wert["Montag Backup"]="backupMo.sh"
|
||||
Wert["Dienstag Backup"]="backupDi.sh"
|
||||
Wert["Mittwoch Backup"]="backupMi.sh"
|
||||
|
||||
printf "\n\tBitte Backup auswaehlen: \n\n"
|
||||
#
|
||||
# Das Ausrufezeichen vor der Array Variable gibt die Array Index No.
|
||||
# aus und das @ Zeichen zwischen den [] gibt dann alle Index No. aus.
|
||||
#
|
||||
select Backup in "${!Wert[@]}";
|
||||
do
|
||||
BackupScript=${Wert[${Backup}]}
|
||||
Title="${Backup}"
|
||||
printf "\n\tDas ${Title} mit dem Script ${BackupScript} wird ausgefuehrt.\n\n"
|
||||
#~/${BackupScript}
|
||||
exit 0
|
||||
done
|
||||
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
Wdr2="http://www.wdr2.de"
|
||||
Sport="http://www.sportschau.de"
|
||||
|
||||
printf "\n\tBitte Web Seite auswaehlen: \n\n"
|
||||
select A in WDR2\ Seite Sportschau\ Seite; # \ maskiert ein Leerzeichen
|
||||
do
|
||||
case $A in
|
||||
WDR*)
|
||||
printf "\n\tFolgende URL wird aufgerufen: ${Wdr2}.\n\n"
|
||||
firefox ${Wdr2}
|
||||
exit 0
|
||||
;;
|
||||
Sport*)
|
||||
printf "\n\tFolgende URL wird aufgerufen: ${Sport}.\n\n"
|
||||
firefox ${Sport}
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
# Als Tabelle
|
||||
printf "|%23s | %-30s |\n" "Username" "Homedir"
|
||||
printf "+%23s + %-30s +\n" "-----------------------" "------------------------------"
|
||||
while IFS=: read BENUTZERNAME A B C D HOMEDIR E; do
|
||||
printf "|%23s | %-30s |\n" $BENUTZERNAME $HOMEDIR
|
||||
done < /etc/passwd
|
||||
printf "+%23s + %-30s +\n" "-----------------------" "------------------------------"
|
||||
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
pheader()
|
||||
{
|
||||
printf "+"
|
||||
for ((i=1;i<=${1};i++));do printf "-"; done
|
||||
printf "+"
|
||||
for ((i=1;i<=${2};i++));do printf "-"; done
|
||||
printf "+\n"
|
||||
}
|
||||
declare -i a b
|
||||
a=0
|
||||
b=0
|
||||
|
||||
while IFS=";" read f1 f2; do
|
||||
if [ ${#f1} -gt ${a} ];
|
||||
then
|
||||
a=${#f1}
|
||||
fi
|
||||
if [ ${#f2} -gt ${b} ];
|
||||
then
|
||||
b=${#f2}
|
||||
fi
|
||||
done < data.txt
|
||||
|
||||
# print table header
|
||||
|
||||
pheader ${a} ${b}
|
||||
printf "|%${a}s|%-${b}s|\n" "First" "Last"
|
||||
printf "|%${a}s|%-${b}s|\n" "Name" "Name"
|
||||
pheader ${a} ${b}
|
||||
|
||||
# print table values
|
||||
while IFS=";" read f1 f2; do
|
||||
printf "|%${a}s|%-${b}s|\n" $f1 $f2
|
||||
done < ./data.txt
|
||||
pheader ${a} ${b}
|
||||
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env bash
|
||||
#==========================================================================
|
||||
# Function: scrypt
|
||||
#==========================================================================
|
||||
# Encode and Decode a string.
|
||||
scrypt() {
|
||||
COLOR_GREEN='\033[0;32m'
|
||||
COLOR_BLUE='\033[0;34m'
|
||||
RESET='\033[0m'
|
||||
if [ $# -eq 0 ]
|
||||
then
|
||||
printf "${COLOR_BLUE} Syntax und Info mit -h oder --help.${RESET}\n"
|
||||
fi
|
||||
|
||||
while [ $# -gt 0 ]
|
||||
do
|
||||
case $1 in
|
||||
-h|--help)
|
||||
printf "\n"
|
||||
printf "${COLOR_GREEN}Syntax:${RESET}\n"
|
||||
printf " $(basename $0) [-h|--help] [-e] [-d]\n\n"
|
||||
printf "${COLOR_GREEN}-e:${RESET}\n"
|
||||
printf " Verschlüsseln eines Strings.\n\n"
|
||||
printf "${COLOR_GREEN}-d:${RESET}\n"
|
||||
printf " Entschlüsslen eines Secrets.\n\n"
|
||||
;;
|
||||
-v|--version)
|
||||
printf "$(basename $0) ${Version}\n"
|
||||
printf "Copyright (C) 2025 Seab@er Software\n"
|
||||
printf "Lizenz GPLv3 +: GNU GPL Version 3 oder hoeher <https://www.gnu.org/licenses/gpl.html>\n"
|
||||
printf "Dies ist eine freie Software : Sie koennen sie aendern und weitergeben.\n"
|
||||
printf "Es gibt keinerlei Garantien , soweit wie es das Gesetz erlaubt.\n\n"
|
||||
printf "Geschrieben von Uwe Schimanski\n"
|
||||
;;
|
||||
-e|--encode)
|
||||
secret=$(echo ""$2"" | openssl enc -e -des3 -base64 -pass pass:Password -pbkdf2)
|
||||
printf "${COLOR_GREEN} Secret:${RESET} ${secret}\n"
|
||||
shift 2
|
||||
;;
|
||||
-d|--dencode)
|
||||
secret=$(echo ""$2"" | openssl enc -d -des3 -base64 -pass pass:Password -pbkdf2)
|
||||
printf "${COLOR_GREEN} Secret:${RESET} ${secret}\n"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
printf "Unbekannte Option: $1\n" 1>&2
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
scrypt $1
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Generate MAC-Address and UUID
|
||||
# Author: Uwe Schimanski
|
||||
# Version: 19.01.08
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
printf "\nGenereate MAC-Address with prefix\n=================================\n"
|
||||
printf "MAC: 00-60-2F-%02X-%02X-%02X\n" $[RANDOM%256] $[RANDOM%256] $[RANDOM%256]
|
||||
printf "MAC: 00-60-2F-" && cut -b 7-11,24-26 /proc/sys/kernel/random/uuid
|
||||
printf "\nGenerate MAC-Address without prefix\n"
|
||||
printf "===================================\n"
|
||||
printf "MAC: %02X-%02X-%02X-%02X-%02X-%02X\n" $[RANDOM%256] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256] $[RANDOM%256]
|
||||
|
||||
UUID1=$(tr -dc a-h0-9 < /dev/random | head -c 8 | xargs)
|
||||
UUID2=$(tr -dc a-h0-9 < /dev/random | head -c 4 | xargs)
|
||||
UUID3=$(tr -dc a-h0-9 < /dev/random | head -c 4 | xargs)
|
||||
UUID4=$(tr -dc a-h0-9 < /dev/random | head -c 4 | xargs)
|
||||
UUID5=$(tr -dc a-h0-9 < /dev/random | head -c 12 | xargs)
|
||||
printf "\nGenerate UUID\n"
|
||||
printf "=============\n"
|
||||
printf "UUID: $UUID1-$UUID2-$UUID3-$UUID4-$UUID5\n"
|
||||
printf "UUID: " && cat /proc/sys/kernel/random/uuid
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/bin/env bash
|
||||
# Laufzeiterstelltes Script
|
||||
#
|
||||
printf "\n\tHier geht es los!\n"
|
||||
ls -lash
|
||||
@@ -0,0 +1,8 @@
|
||||
#!/usr/bin/bash
|
||||
# Laufzeiterstelltes Script mit Taps
|
||||
#
|
||||
if test -r /home/uws/bin/test.txt
|
||||
then
|
||||
printf "\n\tHier geht es los!\n"
|
||||
ls -lash
|
||||
fi
|
||||
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env bash
|
||||
#==============================================================================
|
||||
# FILE: backup.sh
|
||||
#
|
||||
# USAGE: backup.sh
|
||||
#
|
||||
# DESCRIPTION: Backup mit Zaehlnummer
|
||||
#
|
||||
# OPTIONS:
|
||||
# REQUIREMENTS:
|
||||
# BUGS: ---
|
||||
# NOTES:
|
||||
# AUTHOR: Uwe Schimanski
|
||||
# COMPANY:
|
||||
# MAIL: uschimanski@seabaer-net.eu
|
||||
# COPYRIGHT: © 2025 Uwe Schimanski
|
||||
# VERSION: 25.10.03
|
||||
# CREATED: 03.10.2025
|
||||
# REVISION:
|
||||
#==============================================================================
|
||||
BACKUPDIR=/daten/backup
|
||||
SOURCEDIR=/daten/bilder
|
||||
TIMESTAMP=backup-timestamp.dat
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Backup Verzeichnis vorhanden?
|
||||
#------------------------------------------------------------------------------
|
||||
if [ ! -d "${BACKUPDIR}" ]; then
|
||||
echo "Das Verzeichnis ${BACKUPDIR} ist nicht vorhanden"
|
||||
echo "und wird nun angelegt! "
|
||||
mkdir -p ${BACKUPDIR}
|
||||
fi
|
||||
|
||||
set -- ${BACKUPDIR}/backup-???.tgz # Alle Backups einlesen in $1, $2 usw.
|
||||
lastname=${!#} # Letzter Backup Name
|
||||
backupnr=${lastname##*backup-} # Pfad und backup- entfernen
|
||||
backupnr=${backupnr%%.*} # Alles hinter dem ersten "." Entfernen
|
||||
backupnr=${backupnr//\?/0} # Keine Backups vorhanden, dann 0
|
||||
backupnr=$[10#${backupnr}] # Fuehrende Nullen entfernen, (siehe in
|
||||
# der Bash-Manpage unter base#)
|
||||
|
||||
if [ "$[backupnr++]" -ge 999 ]; then # Erhoehen des Wertes um 1
|
||||
echo "Error: Schon 999 Backups vorhanden! "
|
||||
exit 1
|
||||
fi
|
||||
|
||||
backupnr=000${backupnr} # Nullen voranstellen
|
||||
backupnr=${backupnr: -3} # Die letzten 3 Ziffern herausschneiden,
|
||||
filename=backup-${backupnr}.tgz
|
||||
echo "Sichere veraenderte Daten in ${filename}."
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
# Es erfolgt ein inkrementelles Backup, Schalter -g
|
||||
#------------------------------------------------------------------------------
|
||||
tar -czf ${BACKUPDIR}/${filename} -g ${BACKUPDIR}/${TIMESTAMP} ${SOURCEDIR}
|
||||
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
while true
|
||||
do
|
||||
printf "\tCommand: "
|
||||
read
|
||||
eval $REPLY
|
||||
done
|
||||
@@ -0,0 +1,5 @@
|
||||
Hans;Wurst
|
||||
Andrea;Krautwurst
|
||||
Paulchen;Panther
|
||||
Karl;Mai
|
||||
Susanne;Sorglos
|
||||
@@ -0,0 +1,4 @@
|
||||
Das ist Zeile 1.
|
||||
Das ist Zeile 2.
|
||||
Das ist Zeile 3.
|
||||
Das ist Zeile 4.
|
||||
@@ -0,0 +1,3 @@
|
||||
Erste Zeile
|
||||
Zweite Zeile
|
||||
Letzte Zeile
|
||||
@@ -0,0 +1,3 @@
|
||||
server1
|
||||
server2
|
||||
server3
|
||||
@@ -0,0 +1,2 @@
|
||||
# Hier koennte ihre Werbung stehen
|
||||
Wert1;Wert2
|
||||
Reference in New Issue
Block a user