ob-sysinfo.pl 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/env perl
  2. # The script base is taken from http://openbox.org/wiki/Openbox:Pipemenus
  3. use strict;
  4. use warnings;
  5. use autodie;
  6. use POSIX qw(strftime);
  7. use XML::Simple;
  8. use Data::Dumper;
  9. # DISTRO
  10. open (my $issue, "<", "/etc/issue");
  11. my $distro;
  12. while (<$issue>) {
  13. if (/^[^\s]/) {
  14. $distro = (split / /, ((split /\\/)[0]))[0];
  15. last;
  16. }
  17. }
  18. close $issue;
  19. # HOST
  20. my $host = `uname -n`;
  21. chomp $host;
  22. # OS
  23. my $os = `uname -o`;
  24. chomp $os;;
  25. # KERNEL
  26. my $kernel = `uname -r`;
  27. chomp $kernel;
  28. # OPENBOX THEME
  29. my $file = "$ENV{HOME}/.config/openbox/rc.xml";
  30. my $xs1 = XML::Simple->new();
  31. my $doc = $xs1->XMLin($file);
  32. my $obtheme = $doc->{theme}->{'name'};
  33. # LOAD
  34. my $load = (split ' ', (split ':', `uptime`)[4])[0];
  35. chop $load;
  36. # MEMORY (active)
  37. open (my $meminfo, "<", "/proc/meminfo");
  38. my $mem_act;
  39. while (<$meminfo>) {
  40. chomp;
  41. if (/^Active:/) {
  42. $mem_act = int(((split)[-2])/1024);
  43. last;
  44. }
  45. }
  46. close $meminfo;
  47. # UPTIME
  48. my $uptime = `uptime -p | sed 's/.*up //g'`;
  49. # WRITING TO PIPEMENU
  50. print "<openbox_pipe_menu>\n"
  51. . "<separator label=\"$ENV{USER}\@$host \" />\n"
  52. . "<item label=\"OS: $distro $os \" />\n"
  53. . "<item label=\"Kernel: $kernel \" />\n"
  54. . "<item label=\"Theme: $obtheme \" />\n"
  55. . "<item label=\"Load: $load \" />\n"
  56. . "<item label=\"Memory: $mem_act MB\" />\n"
  57. . "<item label=\"Uptime: $uptime \" />\n"
  58. . "</openbox_pipe_menu>\n";