perl -MCPAN -e 'install Net::Jabber'
#!/usr/bin/perl## Author David Cox# Created from various code examples found on the web# Last Modified 2012-07-17 (edited by beer)# History # HTML-changes based on 08/06/2002# adapted d.d. 2006-01-19 by Dieter Demerre to allow html encoded messages## Feel free to use or modify as needed to suit your needs######################################################## MAXWAIT is used because the send message function didn't seem to# like being called too fast. The message would be sent unless I waited a second# or so. You can experiment with it but I just went with 2 seconds.#######################################################use strict;use Net::Jabber qw(Client) ;use Net::Jabber qw(Message) ;use Net::Jabber qw(Protocol) ;use Net::Jabber qw(Presence) ;use HTML::Parse ;require HTML::FormatText;my $len = scalar @ARGV;my $htmlmessage = my $mymessage = "";if ((2 ne $len) && (($len ne 3) || ($ARGV[1] ne "--html"))){ die "Usage...\n notify <jabberid>[,<jabberid>]* [--html] <message>\n";}my @field=split(/,/,$ARGV[0]);use constant RECIPIENT => $ARGV[0];use constant SERVER => 'talk.google.com';use constant PORT => 5222;use constant USER => 'jmeno-pc@gmail.com';use constant PASSWORD => 'heslo';use constant RESOURCE => ' ';use constant MAXWAIT => 2 ;if ("$ARGV[1]" eq "--html"){ $htmlmessage = $ARGV[2]; # printf("pre de-html-ize: htmlmessage = \"$htmlmessage\".\n"); $mymessage = HTML::FormatText->new->format(HTML::Parse::parse_html("$htmlmessage\n"));} else { $htmlmessage = $ARGV[1]; $mymessage = "$htmlmessage";} # printf("htmlmessage = \"$htmlmessage\".\n"); # printf("message = \"$mymessage\".\n");my $connection = Net::Jabber::Client->new();$connection->Connect( "hostname" => SERVER,"port" => PORT ) or die"Cannot connect ($!)\n";my @result = $connection->AuthSend( "username" => USER,"password" =>PASSWORD,"resource" => RESOURCE );if ($result[0] ne "ok") { die "Ident/Auth with server failed: $result[0] - $result[1]\n";}foreach ( @field ) { my $message = Net::Jabber::Message->new(); $message->SetTo($_); $message->SetSubject('Notification'); $message->SetType('chat'); $message->SetBody($mymessage); # printf("Will send text \"%s\".\n",$message->GetBody()); if ("$ARGV[1]" eq "--html") { $message->InsertRawXML("<html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'>$htmlmessage</body></html>"); } $connection->Send($message); sleep(MAXWAIT);}$connection->Disconnect();exit;
chmod +x /root/gtalk.msg
chmod +x /etc/rc.local