On Sat, 12 Dec 1998, Robert wrote:
> hello,
> Is there a good way of notifying all users that , say the server is
> going to be shut down? kinda like for a regular terminal session but
> through some kind of windows messaging?
The following is a perl script I wrote to send a message to all
currently connected machines via 'winpopup'. YMMV, "Sorry
Tennessee!",
etc.
--8<--------------------------------------------------------------
#!/usr/local/bin/perl -w
# turn debugging output on or off w/ this variable
$DEBUG=0;
# file paths - edit if the programs move
$SAMBADIR="/usr/samba/bin";
$SMBSTATUS="$SAMBADIR/smbstatus";
$SMBCLIENT="$SAMBADIR/smbclient";
# Avoid "uninitialized value" warnings
@hosts = ();
# Debugging output
print "hosts = @hosts\n" if($DEBUG);
# Open smbstatus' standard output
open SMBSTATUS, "$SMBSTATUS |";
# Loop over smbstatus output
while(<SMBSTATUS>)
{
# Do this if you haven't found the header line yet
unless($foundline)
{
# If you find the header line...
if(/^--/)
{
# Set the flag
$foundline = 1;
} else
# If not...
{
# Skip to the next line
next;
}
# Do this after finding the header line
}else
{
# Do this if you haven't found a blank line
unless($blankline)
{
# If you find a blank line...
if(/^\s*$/)
{
# Set the flag
$blankline = 1;
# If not...
}else
{
# Split on whitespace
@vars = split /\s+/;
# Set $host to the fifth element of @vars
$host = $vars[4];
# Debugging output
print "hosts = @hosts\n" if($DEBUG);
# IF $host is not in @hosts...
unless(scalar grep { /$host/ } @hosts)
{
# Put $host in @hosts
push @hosts, $host;
# Debugging output
print "host = $host\n" if($DEBUG);
}
# Skip to the next line
next;
}
}
}
}
# Prompt for the message
print "Type your message, ending it with a Control-D\n";
# While they're still typing...
while(<>)
{
# Store each line in $input
$input .= $_;
}
# Do this once for each element in @hosts
foreach $host (@hosts)
{
# Open smbclinet's standard input
open SMBCLIENT, "| $SMBCLIENT -M $host";
# print the message
print SMBCLIENT $input;
# Close smbclient
close SMBCLIENT;
}
------------------------------------------------------------>8----
--
Scott D. Webster swebster@carroll.com
Etc Services Voice: 201.385.7113
Linux, Unix, & TCP/IP Network Consulting Pager: 800.379.2402