lilalo
view l3bashrc @ 71:d499fa3b2af1
Na lilalo@moskau.xt.vpn uspeshno zavelos i\
zarabotalo. + Sohranenie istorii pri vyhode
zarabotalo. + Sohranenie istorii pri vyhode
author | devi |
---|---|
date | Sat Feb 04 00:47:22 2006 +0200 (2006-02-04) |
parents | 6f5ad37fc8d9 |
children | 0ffdebbccfce |
line source
1 #!/bin/sh
4 _l3_start()
5 {
6 L3_TTY=`tty`
7 proc_on_the_term=`w | grep "${L3_TTY##/dev/}" | awk '{print $8;}'`
8 # freeBSD:
9 [ -n "$bsd" ] && \
10 proc_on_the_term=`w | grep "${L3_TTY##/dev/tty}" | awk '{print $6;}'`
12 if [ -n "$proc_on_the_term" ] && echo $proc_on_the_term | grep -qv script
13 then
14 _l3_start_session
15 _l3_run_script
16 else
17 _l3_env
18 _l3_prompt
19 fi
20 }
22 _l3_env()
23 {
24 trap _l3_close_session 2
25 trap _l3_close_session EXIT
26 true
27 }
29 _l3_prompt()
30 {
31 export PS1='\[`
32 a="$?";
33 HIDDEN=$([ "$a" = 0 ] || echo -n ^"$a")$(echo -n _${UID}_)$(echo -n _$$_)$(date\
34 +"%j$(cat ${LMHOME}/lab 2>/dev/null) %H:%M:%S");
35 echo $HIDDEN`\033[50D\033[K\][\u@\h:\W]\$ '
36 }
38 _l3_start_session()
39 {
40 export L3_SESSION_ID=${L3_TTY##*/}-$$
41 export L3_HOME=~/.lilalo/
42 mkdir -p $L3_HOME
44 uname -a | grep -qi bsd && bsd=yes
45 parent=`cat /proc/$PPID/cmdline 2> /dev/null`
46 system=`uname -rs`
47 login_from=`who | grep "${tty##/dev/}" | awk '{print $6;}' | tr -d '()'`
48 #[ -n "$bsd" ] && login_from="" #FIXME!
49 start_time=`date +%s`
50 hostname=`hostname -f 2> /dev/null`
51 [ -n "$bsd" ] && hostname=`hostname`
53 cat <<INFO > $L3_HOME/$L3_SESSION_ID.info
54 <session>
55 <local_session_id>$L3_SESSION_ID</local_session_id>
56 <hostname>$hostname</hostname>
57 <user>$USER</user>
58 <uid>$UID</uid>
59 <login_from>$login_from</login_from>
60 <tty>$tty</tty>
61 <system>$system</system>
62 <parent>$parent</parent>
63 <ppid>$PPID</ppid>
64 <pid>$$</pid>
65 <start_time>$start_time</start_time>
66 </session>
67 INFO
69 unset parent system login_from start_time hostname
70 }
72 _l3_run_script()
73 {
74 uname -a | grep -qi bsd && bsd=yes
75 flush="-f" #linux
76 [ -n "$bsd" ] && flush="-t 0" #freebsd
77 exec script $flush -q $L3_HOME/${L3_SESSION_ID}.script
78 }
80 _l3_close_session()
81 {
82 (
83 echo '<history>'
84 history | sed 's/&/\&/; s/</\</g; s/>/\>/g'
85 echo '</history>'
86 ) >> $L3_HOME/$L3_SESSION_ID.info
87 }