1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
my $datei0 = "/proc/cpuinfo"; open (my $out_fh, ">>", "datei.txt") or die ("Error : $! \n"); open (my $in_fh, "<", datei0) or die ("Error : $! \n"); my $i=0; while (my $zeile = <$in_fh>) { next if $zeile =~ m/\b^processor\b/i; { print $out_fh "$zeile \n";} $i++; chomp ($zeile); print $out_fh "$zeile \n"; } close ($in_fh) or die ("Error .....$datei0: $! \n"); close ($out_fh) or die ("Error .....von 'datei.txt': $! \n"); exit (0);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/usr/bin/perl use strict; use warnings; my @cpuinfo = `cat /proc/cpuinfo`; open (my $writefile, '>',"cpuinfo.txt") or die $!; foreach my $selected_cpuinfo (@cpuinfo) { chomp($selected_cpuinfo); if ($selected_cpuinfo =~ m/^processor/ || $selected_cpuinfo =~ m/^cpu MHz/ ) { print "CPUINFO: $selected_cpuinfo\n"; print $writefile "$selected_cpuinfo\n"; } } close($writefile);
1 2 3 4 5 6 7 8 9 10 11 12
my $datei0 = "/proc/cpuinfo"; open (my $out_fh, ">", "datei.txt") or die ("Error : $! \n"); open (my $in_fh, "<", $datei0) or die ("Error : $! \n"); chomp ($zeile); while (my $zeile = <$in_fh>) { if ($zeile =~ m/^processor/ || $zeile =~ m/^cpu MHz/) { print $out_fh "$zeile \n"; } } close ($in_fh) or die ("Error .....$datei0: $! \n"); close ($out_fh) or die ("Error .....von 'datei.txt': $! \n"); exit (0);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/usr/bin/perl use strict; use warnings; my $datei0 = "/proc/cpuinfo"; open (my $out_fh, ">", "datei.txt") or die ("Error : $! \n"); open (my $in_fh, "<", $datei0) or die ("Error : $! \n"); while (my $zeile = <$in_fh>) { chomp ($zeile); if ($zeile =~ m/^processor/ || $zeile =~ m/^cpu MHz/) { print $out_fh "$zeile \n"; } } close ($in_fh) or die ("Error .....$datei0: $! \n"); close ($out_fh) or die ("Error .....von 'datei.txt': $! \n"); exit (0);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#!/usr/bin/perl use strict; use warnings; #die Inhalte der Systemfiles my @cpuinfo = `cat /proc/cpuinfo`; my @meminfo = `cat /proc/meminfo`; # deine Datenstruktur my %systeminfo = ( "/proc/cpuinfo" => \@cpuinfo, "/proc/meminfo" => \@meminfo, ); #das ganze referenziert my $systeminfo_ref = \%systeminfo; open (my $writefile, '>',"systeminfo.txt") or die $!; #Zugriff auf die CPU Informationen foreach my $selected_cpuinfo ( @{ $systeminfo_ref->{"/proc/cpuinfo"} } ) { chomp($selected_cpuinfo); if ($selected_cpuinfo =~ m/^processor/ || $selected_cpuinfo =~ m/^cpu MHz/ ) { print "CPUINFO: $selected_cpuinfo\n"; print $writefile "$selected_cpuinfo\n"; } } #Zugriff auf die mem infos foreach my $selected_meminfo ( @{ $systeminfo_ref->{"/proc/meminfo"} } ) { chomp($selected_meminfo); print "MEMINFO: $selected_meminfo\n"; #schreibt noch alles ungefiltert nach systeminfo.txt print $writefile "$selected_meminfo\n"; } close($writefile);
1 2
my @cpuinfo = `cat /proc/cpuinfo` or die "no cpuinfo #Error:$!\n"; my @meminfo = `cat /proc/meminfo` or die "no meminfo #Error:$!\n";
print $writefile "$selected_cpuinfo\n";
print $writefile "$selected_cpuinfo\n" or die "#Error:$!";
print $writefile "$selected_meminfo\n";
print $writefile "$selected_meminfo\n" or die "#Error:$!";
close($writefile);
close($writefile) or die "#Error:$!";
Guest guestDie Testdatei syteminfo.txt immer noch leer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %SysInfo; get_cpu_info(\%SysInfo); get_mem_info(\%SysInfo); # Debug print Dumper(\%SysInfo); open(OUTFILE, "> ./sysinfo.txt") or die("$!"); foreach my $section (keys %SysInfo) { printf(OUTFILE "=== %s ===\n",$section); foreach my $name (keys( %{$SysInfo{$section}} )) { printf(OUTFILE "%s\t==>\t%s\n",$name, $SysInfo{$section}{$name}); } } close(OUTFILE); exit(0); sub get_cpu_info { my ($refSi) = @_; open(CPUINFO, "/proc/cpuinfo") or die("$!"); my @relevant_lines = grep(/(^processor|^cpu MHz)/, <CPUINFO>); close(CPUINFO); my $current_cpu; foreach my $info (@relevant_lines) { if ($info =~ /processor\s*:\s*(\d+)/) { $current_cpu = $1; } elsif ($info =~ /cpu MHz\s*:\s+(\S+)/) { $$refSi{'Central Processing Units'}{$current_cpu} = $1; } } } sub get_mem_info { my ($refSi) = @_; open(MEMINFO, "/proc/meminfo") or die("$!"); my @relevant_lines = grep(/(^MemTotal|^MemFree|^Buffers|^Cached)/, <MEMINFO>); close(MEMINFO); foreach my $info (@relevant_lines) { if ($info =~ /^(\w+):\s+(\d+)\s+(\w+)$/) { my $name = $1; my $amount = $2; my $unit = $3; $$refSi{'Memory Information'}{$name} = "$amount $unit"; } } }
1
2
3
4
5
6
7
8
9
10
11
$VAR1 = {
'Memory Information' => {
'Cached' => '143120 kB',
'Buffers' => '177556 kB',
'MemTotal' => '502984 kB',
'MemFree' => '65356 kB'
},
'Central Processing Units' => {
'0' => '736.546'
}
};
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
get_part_info (\%SysInfo); sub get_part_info { my ($refSi) = @_; open (PARTITIONS, "/proc/partitions") or die ("$!"); my @relevant_lines = grep (/(^#blocks|^name)/, <PARTITIONS>); close (PARTITIONS); my $current_partitions; foreach my $info (@relevant_lines) { if ($info =~ /#blocks\s*: \s*(\d+)/) { $current_partitions = $1; elsif ($info =~ /name \s*: \s* (\S+)/){ $$refSi {'Partitions Infos'} {$current_partitions} = $1; }}} }
1
2
3
4
5
6
$ cat /proc/partitions
major minor #blocks name
8 0 156289847 sda
8 1 1502046 sda1
8 2 60002775 sda2
1
2
3
4
5
- Backslash found where operator expected at dateiname.pl line 58, near ´)\' (Missing operator \?)
- Unrecognized escape \s passed through at dateiname.pl line58
- Syntax error at dateiname.pl line 58, near "+)"
- Substitution replacement not terminated at dateiname.pl line 58
line 58: my $regex = gr/(\d+)\s+(\d+)\s+(\d+)\s+(\w+)/;
code_153554_2.txt syntax OK
line 58: my $regex = gr/(\d+)\s+(\d+)\s+(\d+)\s+(\w+)/;
open (my $writefile, '>',"systeminfo.txt") or die $!;
open (my $writefile, ">","systeminfo.txt") or die $!;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/perl
use strict;
use 5.010;
use warnings;
my @cpuinfo = `cat /proc/cpuinfo`;
foreach my $selected_cpuinfo (@cpuinfo) {
chomp($selected_cpuinfo);
if ($selected_cpuinfo =~ m/^processor/ || $selected_cpuinfo =~ m/^cpu/ ) {
print "CPUINFO: $selected_cpuinfo\n";
}
}
Quotewolf@emma:~> cat /proc/cpuinfo
processor :
vendor_id :
cpu family : 6
model : 23
model name : Intel(R) Core(TM)2 Quad CPU Q8400 @ 2.66GHz CPUINFO: processor : 1
stepping : 10
cpu MHz : 2000.000
cache size : 2048 KB
physical id : 0
siblings : 4
core id : 0
cpu cores : 4
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 13
...
QuoteCPUINFO: processor : 0
CPUINFO: cpu family : 6
CPUINFO: cpu MHz : 2000.000
CPUINFO: cpu cores : 4
CPUINFO: cpuid level : 13
CPUINFO: processor : 1
...
$selected_cpuinfo =~ s/\t/#/g;
QuoteCPUINFO: processor#: 0
CPUINFO: cpu family#: 6
CPUINFO: cpu MHz##: 736.546
CPUINFO: cpuid level#: 2