lilalo
diff l3-agent @ 77:e56f21c44faf
Под root'ом приглашение красного цвета
author | devi |
---|---|
date | Mon Feb 13 19:28:51 2006 +0200 (2006-02-13) |
parents | 35e0d61c820d |
children | d28dda8ea18f |
line diff
1.1 --- a/l3-agent Tue Feb 07 12:51:03 2006 +0200 1.2 +++ b/l3-agent Mon Feb 13 19:28:51 2006 +0200 1.3 @@ -196,12 +196,27 @@ 1.4 (.*) # command line 1.5 ) 1.6 '; 1.7 - #my $cline_re = qr/$cline_re_base(?:$cline_re_base|$)/x; 1.8 - #my $cline_re = qr/(?:$cline_re_base)*$cline_re_base$/x; 1.9 my $cline_re = qr/$cline_re_base/sx; 1.10 - my $cline_re1 = qr/$cline_re_base\x0D/sx; 1.11 my $cline_re2 = qr/$cline_re_base$/sx; 1.12 1.13 + my $cline_re_v2_base = qq' 1.14 + ( 1.15 + v2[\#] # version 1.16 + ([0-9]+)[\#] # history line number 1.17 + ([0-9]+)[\#] # exitcode 1.18 + ([0-9]+)[\#] # uid 1.19 + ([0-9]+)[\#] # pid 1.20 + ([0-9]+)[\#] # time 1.21 + (.*?)[\#] # pwd 1.22 + .\\[1024D.\\[K # killing symbols 1.23 + (.*?([\$\#]\\s?)) # prompt 1.24 + (.*) # command line 1.25 + ) 1.26 + '; 1.27 + 1.28 + my $cline_re_v2 = qr/$cline_re_v2_base/sx; 1.29 + my $cline_re2_v2 = qr/$cline_re_v2_base$/sx; 1.30 + 1.31 my $vt = Term::VT102->new ( 'cols' => $Config{"terminal_width"}, 1.32 'rows' => $Config{"terminal_height"}); 1.33 my $cline_vt = Term::VT102->new ('cols' => $Config{"terminal_width"}, 1.34 @@ -210,7 +225,7 @@ 1.35 my $converter = Text::Iconv->new($Config{"encoding"}, "utf-8") 1.36 if ($Config{"encoding"} && $Config{"encoding"} !~ /^utf-8$/i); 1.37 1.38 - print "Loading lm-scripts...\n" if $Config{"verbose"} =~ /y/; 1.39 + print "Parsing lab scripts...\n" if $Config{"verbose"} =~ /y/; 1.40 1.41 my $file; 1.42 my $skip_info; 1.43 @@ -266,6 +281,8 @@ 1.44 1.45 $file =~ m@.*/(.*?)-.*@; 1.46 1.47 + print "+- processing file $file\n" if $Config{"verbose"} =~/y/; 1.48 + 1.49 my $tty = $1; 1.50 my $first_pass = 1; 1.51 my %cl; 1.52 @@ -289,7 +306,7 @@ 1.53 $cl{"local_session_id"} = $local_session_id; 1.54 # Parse new command 1.55 $cl{"uid"} = $3; 1.56 - $cl{"euid"} = $cl{"uid"}; # Если в команде обнаружится sudo, euid поменяем на 0 1.57 + #$cl{"euid"} = $cl{"uid"}; # Если в команде обнаружится sudo, euid поменяем на 0 1.58 $cl{"pid"} = $4; 1.59 $cl{"day"} = $5; 1.60 $cl{"lab"} = $6; 1.61 @@ -317,7 +334,7 @@ 1.62 $cline_vt->reset(); 1.63 1.64 my %commands = extract_commands_from_cline($cl{"cline"}); 1.65 - $cl{"euid"}=0 if defined $commands{"sudo"}; 1.66 + #$cl{"euid"}=0 if defined $commands{"sudo"}; 1.67 my @comms = sort { $commands{$a} cmp $commands{$b} } keys %commands; 1.68 $cl{"last_command"} = $comms[$#comms] || ""; 1.69 1.70 @@ -371,9 +388,6 @@ 1.71 $vt->reset(); 1.72 1.73 1.74 - # Classifying the command line 1.75 - 1.76 - 1.77 # Save 1.78 if (!$Config{"lab"} || $cl{"lab"} eq $Config{"lab"}) { 1.79 # Changing encoding 1.80 @@ -391,6 +405,130 @@ 1.81 } 1.82 next; 1.83 } 1.84 + 1.85 + 1.86 + elsif (m/$cline_re_v2/) { 1.87 + 1.88 + 1.89 +# Разбираем командную строку версии 2 1.90 + 1.91 + 1.92 + s/.*\x0d(?!\x0a)//; 1.93 + m/$cline_re2_v2/gs; 1.94 + 1.95 + $commandlines_loaded++; 1.96 + $last_output_length=0; 1.97 + 1.98 + # Previous command 1.99 + my %last_cl = %cl; 1.100 + 1.101 + $cl{"local_session_id"} = $local_session_id; 1.102 + # Parse new command 1.103 + $cl{"history"} = $2; 1.104 + my $err = $3; 1.105 + $cl{"uid"} = $4; 1.106 + #$cl{"euid"} = $cl{"uid"}; # Если в команде обнаружится sudo, euid поменяем на 0 1.107 + $cl{"pid"} = $5; 1.108 + $cl{"time"} = $6; 1.109 + $cl{"pwd"} = $7; 1.110 + #$cl{"fullprompt"} = $8; 1.111 + $cl{"prompt"} = $9; 1.112 + $cl{"raw_cline"}= $10; 1.113 + 1.114 + { 1.115 + use bytes; 1.116 + $cl{"raw_start"} = tell (FILE) - length($1); 1.117 + $cl{"raw_output_start"} = tell FILE; 1.118 + } 1.119 + $cl{"raw_file"} = $file; 1.120 + 1.121 + $cl{"err"} = 0; 1.122 + $cl{"output"} = ""; 1.123 + #$cl{"tty"} = $tty; 1.124 + 1.125 + $cline_vt->process($cl{"raw_cline"}."\n"); 1.126 + $cl{"cline"} = $cline_vt->row_plaintext (1); 1.127 + $cl{"cline"} =~ s/\s*$//; 1.128 + $cline_vt->reset(); 1.129 + 1.130 + my %commands = extract_commands_from_cline($cl{"cline"}); 1.131 + #$cl{"euid"} = 0 if defined $commands{"sudo"}; 1.132 + my @comms = sort { $commands{$a} cmp $commands{$b} } keys %commands; 1.133 + $cl{"last_command"} 1.134 + = $comms[$#comms] || ""; 1.135 + 1.136 + if ( 1.137 + $Config{"suppress_editors"} =~ /^y/i 1.138 + && grep ($_ eq $cl{"last_command"}, @{$Config{"editors"}}) 1.139 + || $Config{"suppress_pagers"} =~ /^y/i 1.140 + && grep ($_ eq $cl{"last_command"}, @{$Config{"pagers"}}) 1.141 + || $Config{"suppress_terminal"}=~ /^y/i 1.142 + && grep ($_ eq $cl{"last_command"}, @{$Config{"terminal"}}) 1.143 + ) { 1.144 + $cl{"suppress_output"} = "1"; 1.145 + } 1.146 + else { 1.147 + $cl{"suppress_output"} = "0"; 1.148 + } 1.149 + $skip_info = 0; 1.150 + 1.151 + 1.152 + if ($Config{verbose} =~ /y/i) { 1.153 + print "| " if $commandlines_loaded % 15 == 1; 1.154 + print " ",$cl{"last_command"}; 1.155 + } 1.156 + 1.157 + # Processing previous command line 1.158 + if ($first_pass) { 1.159 + $first_pass = 0; 1.160 + next; 1.161 + } 1.162 + 1.163 + # Error code 1.164 + $last_cl{"err"}=$err; 1.165 + $last_cl{"raw_end"} = $cl{"raw_start"}; 1.166 + 1.167 + if (grep ($_ eq $last_cl{"last_command"}, @{$Config{"editors"}})) { 1.168 + bind_diff(\%last_cl); 1.169 + } 1.170 + 1.171 + # Output 1.172 + if (!$last_cl{"suppress_output"} || $last_cl{"err"}) { 1.173 + for (my $i=0; $i<$Config{"terminal_height"}; $i++) { 1.174 + my $line= $vt->row_plaintext($i); 1.175 + next if !defined ($line) ; #|| $line =~ /^\s*$/; 1.176 + $line =~ s/\s*$//; 1.177 + $line .= "\n" unless $line =~ /^\s*$/; 1.178 + $last_cl{"output"} .= $line; 1.179 + } 1.180 + } 1.181 + else { 1.182 + $last_cl{"output"}= ""; 1.183 + } 1.184 + 1.185 + $vt->reset(); 1.186 + 1.187 + 1.188 + # Changing encoding 1.189 + for (keys %last_cl) { 1.190 + next if /raw/; 1.191 + if ($Config{"encoding"} && 1.192 + $Config{"encoding"} !~ /^utf-8$/i) { 1.193 + $last_cl{$_} = $converter->convert($last_cl{$_}) 1.194 + } 1.195 + } 1.196 + push @Command_Lines, \%last_cl; 1.197 + 1.198 + # Сохранение позиции в файле, до которой выполнен 1.199 + # успешный разбор 1.200 + $Script_Files{$file}->{tell} = $last_cl{raw_end}; 1.201 + 1.202 + next; 1.203 + 1.204 + } 1.205 + 1.206 +# Иначе, это строка вывода 1.207 + 1.208 $last_output_length+=length($_); 1.209 #if (!$cl{"suppress_output"} || $last_output_length < 5000) { 1.210 if ($last_output_length < 50000) { 1.211 @@ -408,7 +546,7 @@ 1.212 1.213 } 1.214 if ($Config{"verbose"} =~ /y/) { 1.215 - print "...finished." ; 1.216 + print "\n`- finished.\n" ; 1.217 print "Lines loaded: $commandlines_processed\n"; 1.218 print "Command lines: $commandlines_loaded\n"; 1.219 } 1.220 @@ -419,7 +557,7 @@ 1.221 1.222 sub sort_command_lines 1.223 { 1.224 - print "Sorting command lines...\n" if $Config{"verbose"} =~ /y/; 1.225 + print "Sorting command lines..." if $Config{"verbose"} =~ /y/; 1.226 1.227 # Sort Command_Lines 1.228 # Write Command_Lines to Command_Lines_Index 1.229 @@ -430,13 +568,14 @@ 1.230 } 1.231 1.232 @Command_Lines_Index = sort { 1.233 + $Command_Lines[$index[$a]]->{"time"} <=> $Command_Lines[$index[$b]]->{"time"} || 1.234 $Command_Lines[$index[$a]]->{"day"} cmp $Command_Lines[$index[$b]]->{"day"} || 1.235 $Command_Lines[$index[$a]]->{"hour"} <=> $Command_Lines[$index[$b]]->{"hour"} || 1.236 $Command_Lines[$index[$a]]->{"min"} <=> $Command_Lines[$index[$b]]->{"min"} || 1.237 $Command_Lines[$index[$a]]->{"sec"} <=> $Command_Lines[$index[$b]]->{"sec"} 1.238 } @index; 1.239 1.240 - print "...finished\n" if $Config{"verbose"} =~ /y/; 1.241 + print "finished\n" if $Config{"verbose"} =~ /y/; 1.242 1.243 } 1.244 1.245 @@ -531,22 +670,26 @@ 1.246 #$year = 2004 if ( $cl->{day} > 330 ); 1.247 $year = $Config{year} if $Config{year}; 1.248 # timelocal( $sec, $min, $hour, $mday,$mon,$year); 1.249 - $cl->{time} = timelocal_nocheck($cl->{sec},$cl->{min},$cl->{hour},$cl->{day},0,$year); 1.250 + $cl->{time} ||= timelocal_nocheck($cl->{sec},$cl->{min},$cl->{hour},$cl->{day},0,$year); 1.251 1.252 1.253 # Начинаем вывод команды 1.254 print OUT "<command>\n"; 1.255 for my $element (qw( 1.256 local_session_id 1.257 + history 1.258 + uid 1.259 + pid 1.260 time 1.261 + pwd 1.262 raw_start 1.263 raw_output_start 1.264 raw_end 1.265 raw_file 1.266 tty 1.267 - uid 1.268 err 1.269 last_command 1.270 + history 1.271 )) { 1.272 next unless defined($cl->{"$element"}); 1.273 print OUT "<$element>".$cl->{$element}."</$element>\n"; 1.274 @@ -663,12 +806,11 @@ 1.275 1.276 if ($Config{"mode"} ne "daemon") { 1.277 1.278 -=cut 1.279 - В нормальном режиме работы нужно 1.280 - считать скрипты, обработать их и записать 1.281 - результат выполнения в результирующий файл. 1.282 - После этого завершить работу. 1.283 -=cut 1.284 +# В нормальном режиме работы нужно 1.285 +# считать скрипты, обработать их и записать 1.286 +# результат выполнения в результирующий файл. 1.287 +# После этого завершить работу. 1.288 + 1.289 for my $lab_log (split (/\s+/, $Config{"diffs"} || $Config{"input"})) { 1.290 load_diff_files($lab_log); 1.291 } 1.292 @@ -732,7 +874,7 @@ 1.293 load_cache_stat(); 1.294 load_command_lines($Config{"input"}, $Config{"input_mask"}); 1.295 if (@Command_Lines) { 1.296 - #sort_command_lines; 1.297 + sort_command_lines; 1.298 #process_command_lines; 1.299 print_command_lines($Config{"cache"}); 1.300 }