source: trunk/Distribution/monitor/oscammon.sh@ 21

Last change on this file since 21 was 21, checked in by smurzch2, 14 years ago

Rename from MpCS to OSCam

File size: 2.8 KB
Line 
1#!/bin/bash
2
3CSHOST="localhost"
4CSPORT="988"
5USR="user"
6PWD="passwd"
7NETCAT="nc"
8DELAY=5
9
10get_geo()
11{
12 eval "`echo "$2" | sed -e \"s/^.*${1} /${1}=/g\" -e 's/;.*$//g'`"
13}
14
15do_init()
16{
17 clear
18 sline="`stty -a 2>/dev/null | grep rows 2>/dev/null`"
19 get_geo rows "$sline"
20 get_geo columns "$sline"
21 [ "$rows" -eq 0 ] && rows=25
22 [ "$columns" -eq 0 ] && columns=80
23 rows=`expr $rows - 1`
24 export rows columns
25
26 tput init 2>/dev/null
27 TI_ED="`tput ed 2>/dev/null`"
28 TI_SC="`tput sc 2>/dev/null`"
29 TI_RC="`tput rc 2>/dev/null`"
30 TI_B0="`tput setb 0 2>/dev/null`"
31 TI_B1="`tput setb 5 2>/dev/null`"
32 TI_B2="`tput setb 1 2>/dev/null`"
33 TI_IL="`tput il1 2>/dev/null`"
34 TI_DL="`tput dl1 1 2>/dev/null`"
35 TI_EL="`tput el 2>/dev/null`"
36 export TI_ED TI_B0 TI_B1 TI_B2 TI_IL TI_DL TI_SC TI_RC TI_EL
37}
38
39monitor()
40{
41 $NETCAT -u $CSHOST $CSPORT | awk -W interactive -F"|" '
42 BEGIN{
43 line="---------------------------------------------------------------------";
44 nuser=0;
45 tabsize=(ENVIRON["columns"]-length(line))/2;
46 tab=sprintf("%-*.*s", tabsize, tabsize, "");
47 rows=ENVIRON["rows"];
48 il=ENVIRON["TI_IL"];
49 dl=ENVIRON["TI_DL"];
50 sc=ENVIRON["TI_SC"];
51 rc=ENVIRON["TI_RC"];
52 b0=ENVIRON["TI_B0"];
53 b1=ENVIRON["TI_B1"];
54 b2=ENVIRON["TI_B2"];
55 ed=ENVIRON["TI_ED"];
56 el=ENVIRON["TI_EL"];
57 csr(0, rows);
58 printf("\n%s%s\n", b2, ed);
59 print(tab "Nr User A C Modus Online Sender");
60 print(tab line);
61 csr(5+nuser, rows);
62 cup(5+nuser, 0);
63 printf("%s%s", b0, ed);
64 cup(rows, 0);
65 }
66
67 function csr(row1, row2)
68 {
69 system("tput csr "row1" "row2);
70 }
71
72 function cup(crow, ccol)
73 {
74 system("tput cup "crow" "ccol);
75 }
76
77 /^\[IB....\]/{
78 nuser=0;
79 }
80 /^\[I.....\]/{
81 if (($2!="c") && ($2!="m"))
82 next;
83 printf("%s", sc);
84 cup(4+nuser, 0);
85 ot=$12/60;
86 otm=ot%60; ot/=60;
87 oth=ot%24; ot/=24;
88 if (ot<1)
89 ots=sprintf("%d:%02dh", oth, otm);
90 else
91 ots=sprintf("%dt %dh", ot, oth);
92
93 austate=0+$5;
94 if (austate<0) austate=-austate;
95 printf("%s%s%s%2d %-12.12s%d %d %-10.10s %8.8s %s\n", b2, el,
96 tab, $3, $4, austate, $6, $9, ots, $14);
97 printf("%s", el);
98 nuser++;
99 csr(5+nuser, rows);
100 printf("%s%s", rc, b0);
101 next;
102 }
103 /^\[LOG...\]/{
104 printf("%s%s\n", substr($0, 20, 8), substr($0, 35));
105 next;
106 }
107 {
108 next;
109 }'
110}
111
112do_exit()
113{
114 trap - 1 2 15
115 tput csr 0 $rows 2>/dev/null
116 tput sgr0 2>/dev/null
117 clear
118 exit 0
119}
120
121do_init
122trap do_exit 1 2 15
123
124[ -n "$1" ] && CSHOST="$1"
125[ -n "$2" ] && CSPORT="$2"
126
127while true
128do
129 (
130 while true
131 do
132 echo "login $USR $PWD"
133 sleep 1
134 echo "log on"
135 sleep 1
136 echo "status"
137 sleep $DELAY
138 done
139 ) | monitor
140done
Note: See TracBrowser for help on using the repository browser.