Broadcast Message Script

Im wondering if there is a way I can through a script or a command line get a message to broadcast via the broadcast plugin at certain time intervals. For example the message “Ding” to be broadcast every 2 hours. Any help?

search the forum for my perl script (: or give me a minute to find it.

LG

=> http://www.jivesoftware.org/community/thread.jspa?messageID=126512

I looked over the perl script and im not sure it does exactly what I need. It looks like it logs into the server admin port and then does something with server stats.

What I need is a script or some way to send a broadcast message to all users automatically at certain time intervals. If your script will somehow enable me to do that please explain.

Hi,

it does send a broadcast when it does run. So I post it here again without code format and a fixed get_cookie() method.

LG

#!perl.exe

#my $version = ‘‘v0.01’’;

use strict;

use warnings;

use IO::Socket;

use IO::Handle;

$|=1;

my $message = (defined($ARGV[0]))?"@ARGV":"";

my ($buf, $buflen, $buf2);

  1. adjust this

my $my_servername = “127.0.0.1”;

my $my_adminport = “9090”;

my $my_adminpath = “”; # ‘‘Wifi/’’ if you are using Tomcat and ‘‘Wifi.war’’, don’‘t forget the trailing ‘’/’’

my $my_adminuser = “admin”;

my $my_password = “test”;

my $baseurl = “http://” . $my_servername . “:” . $my_adminport . “/” . $my_adminpath;

my $loginpage = “login.jsp”;

my $broadcastpage = “user-message.jsp”;

my $TRGT_PROTO = ‘‘tcp’’;

my $HTTP_HEADER = "Host: " . $my_servername . “:” . $my_adminport . “\r\n” .

“Content-Type: application/x-www-form-urlencoded\r\n” .

“Connection: close\r\n” .

“Content-Type: text/html; charset=UTF-8\r\n\r\n”;

my $cookie = “”;

  1. login - POST and GET are possible, we will use POST

#printf("############# login #############\n");

$buf = “url=/” . $my_adminpath . $broadcastpage . “&”;

$buf .= “login=true” . “&”;

$buf .= “username=” . $my_adminuser . “&”;

$buf .= “password=” . $my_password;

$buflen=length($buf);

$buf = “POST " . $baseurl . $loginpage . " HTTP/1.0\r\n” .

"Content-Length: " . length($buf) . “\r\n” .

$HTTP_HEADER .

$buf;

&send();

&get_cookie();

#printf("############# sending broadcast #############\n");

$message =~ s/%/%25/g;

$message =~ s/
+/%2b/g;

$message =~ s/&/%26/g;

$buf = “tabs=true” . “&”;

$buf .= “send=true” . “&”;

$buf .= “message=” . $message;

$buflen=length($buf);

$buf = “POST " . $baseurl . $broadcastpage . " HTTP/1.0\r\n” .

"Content-Length: " . length($buf) . “\r\n” .

$cookie . “\r\n” .

$HTTP_HEADER .

$buf;

&send();

#printf("############# success ? #############\n");

if ($buf2 =~ /$broadcastpage?success=true/)

{

printf(“OK\n”);

} else

{

printf(“Error\n”);

exit(3);

};

exit(0);

sub get_cookie()

{

if ($buf2 =~ /(Cookie\s**:\s[^;]**)/)

{

$cookie = $1;

} else

{

printf(“Could not get Cookie / Login”);

exit(1);

};

#printf("############# Cookie: %s\n", $cookie);

};

sub send()

{

#printf("############# Send: %s\n", $buf);

my $sock = new IO::Socket::INET->new(PeerAddr => $my_servername,

PeerPort => $my_adminport, Proto => $TRGT_PROTO);

if (!defined $sock)

{

printf(“Could not create socket.\n”);

exit(2);

};

$sock->send($buf);

$buf = “”;

$buf2 = “”;

while (<$sock>)

{

read($sock, $buf, 1000);

$buf2 .= $buf;

};

close ($sock);

printf("############# Recv: %s\n", $buf2);

};

Thanks. My perl skills aren’'t quite what they used to be. Where in this script do

I include the message I want to send? What other information do I need to know as I only have an introductory level understanding of perl.

Thanks again!

Hi,

the first parameter is used, so you may want to execute

broadcast.pl “Hello World”

You can also set $message=“Hello World”; if you want to use a static message.

It does not support UTF-8 or äöü so far but for ASCII broadcasts it’'s fine.

LG

I ran it, it works perfect! Thanks. Now I just have to find a way to automate the scheduling of its execution.

Try the funny “at” command or Win Cron.

UTF-8 support may be enabled by simpley adding “use uft8;” as line 5. For me with Perl 5.6.1/Windows it does work not right, length() does return the wrong length so I need to add trailing space characaters while Perl 5.8.8/Linux works fine.

LG

I figured out how to use cron on my fedora box which is what im using for server. Thanks for your help!

Nasty,ugly language. No offense to you, just to Perl.