I was fooling around with
perlTk and came up with this snippet. It might be handy for people writing gui programs like log checkers or wanting to use other unix program output.
UPDATED: it now uses the code enhancements
liz suggested. Thanks
liz ;)
#!/usr/bin/perl
#sambastatus in PerlTk
use strict;
use Tk;
use Tk::HList;
my $user=0;
my $top = new MainWindow(-title => 'Samba TK sample');
my $hlist = $top->Scrolled("HList",
-header => 1,
-columns => 7,
-scrollbars => 'osoe',
-width => 80,
-selectbackground => 'SeaGreen3',
)->pack(-expand => 1, -fill => 'both');
#updated with liz example!
my $option = 0;
foreach (qw(user gid pid machine service ip-adres logon)) {
$hlist->header('create', $option++, -text => $_);
}
open SMBST, "smbstatus |grep \)|"; #filters out the nonsense
while(<SMBST>){
(my $service,my $uid,my $gid,my $pid,my $machine,my $ipadres,my $rest)
+ = split /\s+/, $_, 7;
chomp $rest;
$hlist->add($user);
$hlist->itemCreate($user, 0, -text => "$uid");
$hlist->itemCreate($user, 1, -text => "$gid");
$hlist->itemCreate($user, 2, -text => "$pid");
$hlist->itemCreate($user, 3, -text => "$machine");
$hlist->itemCreate($user, 4, -text => "$service");
$hlist->itemCreate($user, 5, -text => "$ipadres");
$hlist->itemCreate($user, 6, -text => "$rest");
$user++;
}
close SMBST;
MainLoop;