| Pastreaza un log al login-urilor si logout-urilor |
|
| Scris de Cypress | ||||||
| Thursday, 22 November 2007 | ||||||
|
#!/bin/bash ########################################################################## # Title : einlog - keep a log file of login and logout time stamps # Author : Heiner Steven < Aceasta adresa e-mail este protejata impotriva spamului, JavaScript trebuie activat pentru a putea vizualiza pagina. > # Date : 1993-12-10 # Requires : # Category : Desktop # SCCS-Id. : @(#) einlog 1.9 05/08/29 ########################################################################## # Description # Keep a log file of the first and the last login # See also # logstat ########################################################################## PN=`basename "$0"` # Program name VER='1.9' : ${LOGFILE:=$HOME/lib/log} : ${TMPDAT:=/tmp/log.$$} lock=$LOGFILE.lock DateForm='%Y-%m-%d %H:%M (%a)' Date=`LANG=C date '+%Y-%m-%d'` currenttime=`LANG=C date "+$DateForm"` usage () { echo >&2 "$PN - keep a log file of login and logout time stamps, $VER usage: $PN {-i | -o} -i: log in -o: log out Log file: $LOGFILE" exit 1 } msg () { for msgLine do echo "$PN: $msgLine" >&2 done } fatal () { msg "$@"; exit 1; } set -- `getopt :haeio "$@" || exit 1` || usage [ $# -lt 1 ] && usage # "getopt" detected an error Mode=login # {login|logout} while [ "$#" -gt 0 ] do case "$1" in -i|-e) Mode=login;; -o|-a) Mode=logout;; --) shift; break;; -h) usage;; -*) usage;; *) break;; # First file name esac shift done # System V date command preferred PATH="/usr/5bin:$PATH" export PATH if mkdir "$lock" >/dev/null 2>&1 then # Aquired lock. Remove it when the program terminates, or after # reception of a signal. trap 'rmdir "$lock" >/dev/null 2>&1' 0 trap "exit 2" 1 2 3 13 15 else fatal "could not create lock: $lock" fi if [ -f "$LOGFILE" ] then : else cat <<-! > "$LOGFILE" # log - login and logout times (first and last login) # created `date +"$DateForm"` ! chmod 600 "$LOGFILE" fi # Only one entry per day. Always add an "EIN" entry if it does not exist # already. grep "EIN: $Date" < "$LOGFILE" > /dev/null || echo "EIN: $currenttime AUS: $currenttime" >> "$LOGFILE" case "$Mode" in login) # "EIN" record was already written. ;; logout) # Keep file time stamp by copying it using "cp -p" cp -p "$LOGFILE" "$TMPDAT" || fatal "cannot create temporary file: $TMPDAT" { grep -v "AUS:.* $Date" < "$LOGFILE" # once per day echo "AUS: $currenttime" } > "$TMPDAT" && mv -f "$TMPDAT" "$LOGFILE" ;; *) usage ;; esac
Only registered users can write comments! Powered by !JoomlaComment 3.12 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved. |
||||||



Debunking the Linux virus myth
Sa speram. Si daca ajunge acolo, sa sper...
Debunking the Linux virus myth
do I smell a frontpage
Debunking the Linux virus myth
Pagina e acolo, atat doar ca e un spatiu...
Un nou articol pe MYLRo.org
dar ce fel de vizite? conteaza sa ai tra...
Debunking the Linux virus myth
page not found
Un nou articol pe MYLRo.org
Articolul il scrisesem mai demult si l-a...
Debunking the Linux virus myth
Wohooo... 5661 de read-uri de ieri si 91...