#!/usr/local/bin/perl # ntwall.pl - by aperrin 1/21/99 - cycle through machines with people logged # in and blast a message to them. Assumes message is on stdin. # Tried to make arguments as much like wall(1M) as possible: # -a will send to all pc's in demogpc's, regardless of login # status, -g doesn't do anything, optional filename will take # stdin from there. #>owner:1 #>group:714 #>mode:0550 #Globals $statdir = "/home/davis/opt/samba/status"; $smbclient = "/usr/LOCAL/samba/bin/smbclient"; $ypcmd = "/bin/ypmatch demogpcs netgroup"; #Main if ($ARGV[0] =~ /^\-/) { if ($ARGV[0] =~ /^\-a|A/) { $allpcs = 1; $infile = $ARGV[1] if $ARGV[1]; } else { print STDERR "$0: illegal option -- $ARGV[0]\n"; print STDERR "Usage: $0 [-a] [filename]\n"; exit 1; } } elsif (-d $statdir) { $allpcs = 0; $infile = $ARGV[0] if $ARGV[0]; } else { print STDERR "$0: $statdir not available, using netgroup instead.\n"; $allpcs = 1; $infile = $ARGV[0] if $ARGV[0]; } @msg = unless $infile; if ($infile) { open (INFILE,"<$infile") || die "Can\'t open $infile: $!\n"; @msg = ; close INFILE; } opendir STATDIR, $statdir; @hosts = grep(!/^\./,readdir(STATDIR)) unless $allpcs; if ($allpcs) { $yphosts = `$ypcmd`; @hosts = split(/\s+/,$yphosts); } $hosts = join(' ; ',@hosts); print STDERR "hosts: $hosts\n"; closedir STATDIR; foreach $host (@hosts) { open(SMBCLIENT,"|$smbclient -M $host") || die "Can\'t open smbclient for $host\n"; foreach $line (@msg) { print SMBCLIENT $line; } close SMBCLIENT }