Advertisement
Dj_Dexter

wifi_status.pl

Sep 25th, 2013
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 1.95 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. sub daemon(){
  4.     umask 0;
  5.     open(STDIN, "</dev/null");
  6.     open(STDOUT,">>/dev/null");
  7.     open(STDERR, ">>/dev/null");
  8.     my $pid = fork;
  9.     exit if $pid;
  10. }
  11.  
  12. sub main(){
  13.         my $bar;
  14.         my ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime();
  15.  
  16.         # You add 1 because the number in $month is based on a starting number of 0.  
  17.         # So, if $month is 0, then $monthnum is 1 (ie:  January)
  18.         # Adding 1 gets you a number from the list below.  
  19.  
  20. my $monthnum = $month + 1;
  21.  
  22. my %monthname = (
  23.                   1 => 'Enero',
  24.                   2 => 'Febrero',
  25.                   3 => 'Marzo',
  26.                   4 => 'Abril',
  27.                   5 => 'Mayo',
  28.                   6 => 'Junio',
  29.                   7 => 'Julio',
  30.                   8 => 'Agosto',
  31.                   9 => 'Septiembre',
  32.                  10 => 'Octubre',
  33.                  11 => 'Noviembre',
  34.                  12 => 'Diciembre',
  35. );
  36.         daemon();
  37.  
  38.         while(1){
  39.  
  40.                 $username = getpwuid($<);
  41.                 $ENV{'HOSTNAME'} =~ /(\w*)/;$hostname = $1;
  42.  
  43.                 `uptime`   =~ /up +([^,]*)/;$uptime = "$1";
  44.  
  45.                 $iwconfig = `/sbin/iwconfig`;
  46.                 $iwconfig =~ /ESSID:(.*)  [\s\S]*(Signal level=.*dBm)?/;
  47.                 $essid = $1;
  48.                 $iwconfig =~ /(Signal level=.*dBm)/;
  49.                 $dBmnumeric = $1;
  50.                 $dBmnumeric =~ s/Signal level=-(\d+) dBm/$1/i;
  51.                 $dBm = '|' x ($dBmnumeric ? ((100-$dBmnumeric)+19)/20 : 0);
  52.  
  53.                 ($sec, $min, $hr, $day, $mes) = localtime(time);
  54.  
  55.  
  56.                 $bar = sprintf("[ESSID:%s;%s]{%-4s}  {%02d/%s - %02d:%02d:%02d} up[%s] %s\@%s",$essid,$dBmnumeric,$dBm,$day,$monthname{$monthnum},$hr,$min,$sec,$uptime,$username,$hostname);
  57.                 `xsetroot -name "$bar"`;
  58.                 sleep(5)
  59.         }
  60. }
  61.  
  62. main;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement