# Pfade für Programme und Dateien
SAC="/usr/local/sbin/sac"
AWK="/usr/bin/gawk"
TAB2PS="/usr/local/bin/blt_wish -f
/root/bin/tab2ps.tcl"
CONV="/usr/bin/convert"
DIR="/root/public_html/userlog"
out0="$DIR/ulog.text"
out1="$DIR/ulog.time"
out2="$DIR/ulog.logins"
out3="$DIR/ulog_other.time"
out4="$DIR/ulog_other.logins"
out5="$DIR/ulog_ttyS1.time"
out6="$DIR/ulog_ttyS1.logins"
# Als Erstes: Schreibberechtigung holen.
xauth merge ~joe/.Xauthority
# In der letzten Zeile der Ausgabe von "last" steht
# der zeitliche Beginn der wtmp-Datei
last | tail -1 >$DIR/wtmpstart
echo "Calculating login count and time of users ..."
echo "Text..."
# Zuerst die aktuelle Statistik in einer HTML-Tabelle
echo "
" >$out0
echo "User | Loginzeit | Logins |
echo Durchschnittliche Loginzeit | " >>$out0
$SAC -adcp | sort -n -r +1 | \
$AWK '{ print "" $1 " | " "" $2 " | " ""
$3 " | " "" $5 " | " "
"}' \
>> $out0
echo "
" >>$out0
# Nun werden mehrere Statistiken generiert
echo "Graphics..."
# Loginzeit und Anzahl Logins von allen Usern
$SAC -adcp | sort -n -r +1 | $AWK '{ print $1, $2 }'
>$out1
$SAC -adcp | sort -n -r +1 | $AWK '{ print $1, $3 }'
>$out2
# Im Beispiel wird angenommen, dass die User
# joe und root sehr oft eingeloggt sind.
# Daher wird für diese eine eigene Graphik erstellt.
echo "Calc. login count/time without joe and root ..."
cat $out1 | grep -v joe | grep -v root >$out3
cat $out2 | grep -v joe | grep -v root >$out4
# Übersicht der Logins per Modem
# (ttyS1)
echo "Calculating login count and time of modem-users"
$SAC -adp -T ttyS1 | sort -n -r +1 | $AWK '{ print $1,
$2 }' >$out5
$SAC -adp -T ttyS1 | sort -n -r +1 | $AWK '{ print $1,
$3 }' >$out6
# Alte Dateien ins old-Verzeichnis verschieben
echo "Moving old tables to old/ ..."
mv -f $DIR/*.jpg $DIR/old/
mv -f $DIR/timestamp $DIR/old
# Konvertierung der Tabellen in Postscript-Graphiken
echo "Generating tables ..."
$TAB2PS $out1 "Login times" "User" "Time"
$TAB2PS $out2 "Login count" "User" "Logins"
$TAB2PS $out3 "Login times without joe and root" "User"
"Time"
$TAB2PS $out4 "Login count without joe and root" "User"
"Logins"
$TAB2PS $out5 "Login times modem" "User" "Time"
$TAB2PS $out6 "Login count modem" "User" "Logins"
# Die aktuellen Werte von Datum und Zeit
date >$DIR/timestamp
# Um die Graphiken im Browser anzusehen, sind die
# Postscript-Dateien ins JPEG-Format zu konvertieren.
echo "Converting *.ps to *.jpg ..."
$CONV "$out1.ps" "$out1.jpg"
$CONV "$out2.ps" "$out2.jpg"
$CONV "$out3.ps" "$out3.jpg"
$CONV "$out4.ps" "$out4.jpg"
$CONV "$out5.ps" "$out5.jpg"
$CONV "$out6.ps" "$out6.jpg"
# Nicht mehr benötigte Postscript-Dateien löschen
echo "Deleting *.ps files ..."
rm -f *.ps
echo "Done."