lilalo

diff l3bashrc @ 155:8ee5e59f1bd3

Локальное хранение и анализ данных с помощью SQlite

Очень много изменений, касающихся работы с sqlite
и локального использования результатов записи.
Подробнее:
README.l3text
author Igor Chubin <igor@chub.in>
date Tue Mar 16 20:05:30 2010 +0200 (2010-03-16)
parents 40d843395547
children a0daf0c3fa52
line diff
     1.1 --- a/l3bashrc	Fri Mar 06 13:34:59 2009 +0600
     1.2 +++ b/l3bashrc	Tue Mar 16 20:05:30 2010 +0200
     1.3 @@ -57,6 +57,7 @@
     1.4  {
     1.5      export L3_SESSION_ID=${RANDOM}${RANDOM}${RANDOM}${RANDOM}-`date +%s`
     1.6      export L3_HOME=~/.lilalo/
     1.7 +    L3_SQLITE=$L3_HOME/report.sqlite
     1.8      mkdir -p $L3_HOME
     1.9  
    1.10      tty=`/usr/bin/tty`
    1.11 @@ -70,6 +71,21 @@
    1.12      hostname=`hostname -f 2> /dev/null`
    1.13      [ -n "$bsd" ] && hostname=`hostname`
    1.14  
    1.15 +    cat <<INFO | perl
    1.16 +use DBI;
    1.17 +use strict;
    1.18 +my \$db = DBI->connect("dbi:SQLite:$L3_SQLITE", "", "",
    1.19 +{RaiseError => 1, AutoCommit => 1});
    1.20 +
    1.21 +\$db->do("CREATE TABLE IF NOT EXISTS sessions (id INTEGER PRIMARY KEY, 
    1.22 +            session TEXT, hostname TEXT, user TEXT, uid TEXT, login_from TEXT, 
    1.23 +            tty TEXT, system TEXT, parent TEXT, ppid TEXT, pid TEXT, start_time TEXT, lang TEXT)");
    1.24 +\$db->do("INSERT INTO sessions VALUES (NULL, '$L3_SESSION_ID', '$hostname', '$USER', '$UID', '$login_from',
    1.25 +            '$tty', '$system', '$parent', '$PPID', '$$',
    1.26 +            '$start_time', '$LANG')");
    1.27 +INFO
    1.28 +    #perl $temp_l3_name #; rm $temp_l3_name; unset temp_l3_name
    1.29 +
    1.30      cat <<INFO > $L3_HOME/$L3_SESSION_ID.info
    1.31  <session>
    1.32      <local_session_id>$L3_SESSION_ID</local_session_id>
    1.33 @@ -258,11 +274,14 @@
    1.34  l3 ()
    1.35  {
    1.36      case "$1" in
    1.37 -        on)
    1.38 -            echo switching on
    1.39 -        ;;
    1.40 -        off)
    1.41 -            echo switcing off
    1.42 +        context)
    1.43 +            if [ -z "$2" ] 
    1.44 +            then
    1.45 +                echo "$L3_CONTEXT"
    1.46 +            else
    1.47 +                echo $2 | grep -q ^/ && L3_CONTEXT="$2" || L3_CONTEXT="$L3_CONTEXT/$2"
    1.48 +                export L3_CONTEXT="`echo $L3_CONTEXT | perl -e '$_=<>; 1 while s@/[^/]*/\.\.@@; print;'`"
    1.49 +            fi
    1.50          ;;
    1.51          cd)
    1.52              echo l3cd="$2" > ~/.l3rc
    1.53 @@ -271,26 +290,10 @@
    1.54              grep ^l3cd= ~/.l3rc | sed s/[^=]*=//
    1.55          ;;
    1.56          *) 
    1.57 -            cat <<EOF
    1.58 -l3 [command]:
    1.59 -
    1.60 -    cd new_context   - change current lilalo context
    1.61 -    pwd              - show current lilalo context
    1.62 -    on               - switch writing on (NOT IMPLEMENTED YET)
    1.63 -    off              - switch writing off (NOT IMPLEMENTED YET)
    1.64 -
    1.65 -EOF
    1.66 +            l3text "$@"
    1.67          ;;
    1.68      esac
    1.69  }
    1.70  
    1.71 -l3cd()
    1.72 -{
    1.73 -    l3 cd "$@"
    1.74 -}
    1.75  
    1.76 -l3pwd()
    1.77 -{
    1.78 -    l3 pwd
    1.79 -}
    1.80