Skripte, Programme und Anderes
|
|
An dieser Stelle sollen nützliche Skripte folgen, auf die teilweise im Buchtext verwiesen wird.
Einige der Skripte sind bewusst einfach gehalten und verzichten zu Gunsten der Verständlichkeit auf
umfangreiche Fehlerbehandlungen. Der Leser sollte diese leicht selbst ergänzen können.
Auch Themen, die nicht unbedingt in den Inhalt des Buches passen, finden ggf. hier ihren Platz.
Das nachfolgend beschriebene Programm ist ein Ersatz für das Unix-Programm crypt, das den
meisten Linux-Distributionen nur in Form einer Bibliotheksroutine beiliegt. Das Programm erwartet als Eingabe
das zu verschlüsselnde Passwort und eine aus 2 alphanumerischen Zeichen bestehende Zeichenkette - das
Salz in der Suppe. Mit Hilfe dieser beiden Zeichen wird die Arbeitsweise des Algorithmus auf eine von 4096
möglichen Arten modifiziert. Die Zeichen können beliebig gewählt werden.
Aber nun das Listing des Programmes:
#include <unistd.h>
#include <stdio.h>
int main (int argc, char** argv)
{
if ( argc != 3 )
{
fprintf(stderr, "%s need two arguments to encrypt\n", argv[0]);
return -1;
}
printf("%s", crypt(argv[1], argv[2] ));
return 0;
} |
Übersetzt wird das Programm mit:
user@sonne> cc crypt.c -o mycrypt -lcrypt |
Ein Aufruf sieht wie folgt aus:
user@sonne> ./mycrypt MyPassword X7
X7xe.8.ZuZ/PE |
Zur Nutzerverwaltung
Abbildung 1: Weiße Schrift auf schwarzem Grund...
Genug von Schwarz und Weiß? Dann gibt es mehrere Möglichkeiten, die Konsole ein
wenig aufzupeppen...
Das Kommando ls kann mittels der Option --color zu einer farbigen Darstellung der Ausgabe
überredet werden. Dazu verwendet ls die in der Datei /etc/DIR_COLORS angegebenen
Informationen.
user@sonne> cat /etc/DIR_COLORS
############### gekürzte Datei #########################
# Configuration file for the color ls utility
# This file goes in the /etc directory, and must be world readable.
# You can copy this file to .dir_colors in your $HOME directory to override
# the system defaults.
# COLOR needs one of these arguments: 'tty' colorizes output to ttys,but not
# pipes. 'all' adds color characters to all output. 'none' shuts colorization
# off.
COLOR tty
# Extra command line options for ls go here.
# Basically these ones are:
# -F = show '/' for dirs, '*' for executables, etc.
# -T 0 = don't trust tab spacing when formatting ls output.
OPTIONS -F -T 0
# Below, there should be one TERM entry for each termtype that is
colorizable
TERM linux
TERM console
TERM con132x25
TERM con132x30
TERM con132x43
TERM con132x60
TERM con80x25
# EIGHTBIT, followed by '1' for on, '0' for off. (8-bit output)
EIGHTBIT 1
NORMAL 00 # global default, although
everything should be something.
FILE 00 # normal file
DIR 01;34 # directory
LINK 01 # symbolic link
FIFO 40;33 # pipe
SOCK 01;35 # socket
BLK 40;33;01 # block device driver
CHR 40;33;01 # character device driver
# This is for files with execute permission:
EXEC 01;31
# List any file extensions like '.gz' or '.tar' that you would like ls
.tar 00;31 # archives or compressed (red)
.tgz 00;31
.taz 00;31
.lzh 00;31
.zip 00;31
.z 00;31
.bz2 00;31
.jpg 01;35 # image formats
.gif 01;35
.bmp 01;35
.xbm 01;35a |
Mit Hilfe des Kommandos echo lässt sich die Farbe für alle folgenden Ausgaben
steuern:
Aufruf: echo -e "\033[<Flag>;<Farbe>[;<Farbe>]m" |
Als<Flag> sind folgende Codes zulässig: |
00 |
normale Darstellung |
01 |
fette Schrift |
04 |
unterstrichen |
05 |
blinkende Schrift |
07 |
inverse Darstellung |
08 |
verborgene Darstellung (keine Ausgabe) |
|
Als<Farbe> sind folgende Codes zulässig: |
Textfarbe |
Hintergrundfarbe |
30 |
schwarz |
40 |
schwarz |
31 |
rot |
41 |
rot |
32 |
grün |
42 |
grün |
33 |
gelb |
43 |
gelb |
34 |
blau |
44 |
blau |
35 |
violett |
45 |
violett |
36 |
kobaltblau |
46 |
kobaltblau |
37 |
weiß |
47 |
weiß |
|
Die Eingabe user@sonne> echo -e "\033[01;33;41m"
erzeugt folgende Konsolenoptik:
Abbildung 2: Etwas Farbe für die Konsole
Zurück zum Abschnitt Bash.
Die Generierung der Druckversion der Linuxfibel übernimmt ein kombiniertes
Awk- und Bash-Skript. Eine Diskussion des Skript selbst
finden Sie im Abschnitt Bashprogrammierung, Komplexe Anwendungen.
user@sonne> cat printversion.sh
#!/bin/sh
linuxfibel_base=${1:-./}
awk_script=/tmp/`basename $0`.$$
trap 'test -e $awk_script && rm $awk_script' 2 15
test -d $linuxfibel_base || { echo "Verzeichnis $linuxfibel_base existiert nicht"; exit 1;
}
cd $linuxfibel_base
|
test -e vorwort.htm |
|| { echo "Falsches Linuxfibel-Verzeichnis?"; exit 1; } |
test -d printversion |
|| mkdir printversion |
test -L printversion/images |
|| (cd printversion && ln -s ../images) |
cat > $awk_script << EOF
#--------- AWK-SCRIPT BEGINN --------------
#!/usr/bin/awk -f
BEGIN {
DoPrint="true"
IGNORECASE=1
}
/<script language="JavaScript">/ |
{ DoPrint = "false" } |
/<\/head>/ |
{ DoPrint = "true" } |
/<body bgcolor/ |
{ print \$0; DoPrint = "false" } |
/HIER BEGINNT DER TEXT/ |
{ getline; getline; DoPrint = "true" } |
/HIER ENDET DER TEXT/ |
{ getline; print \$0; DoPrint = "false" } |
/<\/body>/ |
{ DoPrint = "true" } |
{
if ( DoPrint == "true") {
print \$0 }
}
#--------- AWK-SCRIPT ENDE ----------------
EOF
chmod +x $awk_script
for i in *.htm; do
$awk_script $i > printversion/$i
done
kill -2 $$
|
Speichern Sie das Skript Programm in eine Datei »printversion.sh« im Linuxfibel-Basisverzeichnis.
Versehen Sie es mit Ausführungsrechten und starten Sie es innerhalb des Linuxfibel-Basisverzeichnisses!
user@sonne> cd Linuxfibel
user@sonne> chmod +x printversion.sh
user@sonne> ./printversion.sh
|
Die konvertierten Seiten werden im Unterverzeichnis »printversion abgelegt.
Sie benötigen hierfür das Paket »htmldoc«, das jeder umfangreichen Distribution
beiliegen sollte. Wichtig ist, dass Sie die HTML-Seiten gemäß der Reihenfolge in der
Linuxfibel dem Kommando zuführen. Leider bleibt Ihnen nichts anderes übrig, als die
einzelnen Seiten von Hand anzugeben (oder aus nachfolgendem Beispielaufruf zu kopieren):
user@sonne> htmldoc --book --webpage -f ~/linuxfibel.pdf
default.htm toc.htm einleitung.htm
vorwort.htm allekapitel.htm entwicklung.htm kapitel1.htm login.htm
logout.htm vkonsole.htm xnavigation.htm dir+file.htm eigentum.htm
hilfe.htm editoren.htm kapitel2.htm command.htm inshelp.htm
eaumleitung.htm proccontrol.htm kapitel3.htm dirstruct.htm storage.htm
kapitel4.htm archiv.htm file+dir.htm helpcmd.htm communication.htm
networkcmd.htm userinfo.htm procctl.htm sysinfo.htm text.htm
weiteres.htm kapitel5.htm distris.htm installbefore.htm debian.htm
redhat.htm suse.htm autoinstall.htm bootman.htm kapitel6.htm shallg.htm
bash.htm bashprog.htm csh.htm cshprog.htm ksh.htm kshprog.htm
kapitel7.htm vi.htm emacs.htm regex.htm grep.htm sed.htm awk.htm
make.htm kapitel8.htm booten.htm backup.htm filesys.htm groupadmin.htm
hwinstall.htm swinstall.htm loginadmin.htm useradmin.htm protocol.htm
securesystem.htm xconfig.htm anxious.htm sax.htm time.htm access.htm
kapitel9.htm xhist.htm xcliserv.htm xsteuerung.htm xlogin.htm fvwm2.htm
kwm.htm gnome.htm xconfigurator.htm xf86cfg.htm xf86conf.htm
xf86config.htm xf86setup.htm kapitel10.htm khist.htm karch.htm
kmodule.htm kprocdat.htm kconf.htm kinst.htm linuxnet.htm nethist.htm
netprot.htm netstruct.htm nethw.htm nettest.htm nettools.htm netdiag.htm
inetd.htm rpc.htm rfc.htm services_use.htm telnet_cli.htm nfs_cli.htm
nis_cli.htm dns_cli.htm dhcp_cli.htm www_cli.htm mail_cli.htm
ftp_cli.htm news_cli.htm samba_cli.htm services_provide.htm
telnet_srv.htm nfs_srv.htm nis_srv.htm dns_srv.htm dhcp_srv.htm
www_srv.htm mail_srv.htm ftp_srv.htm news_srv.htm samba_srv.htm
net_sec.htm wrapper.htm firewall.htm limits.htm license.htm scripts.htm
glossar.htm links.htm register.htm
|
Die Datei »toc.htm« enthält ein Inhaltsverzeichnis und liegt den Paketen ab Version
0.8.2 bei.
Dank
Die PDF-Version entstand nach Hinweisen von Martin Hauptmann und Daniel Münch.
|