9

I have installed ircd-hybrid on my Ubuntu Server (192.168.1.2, example.com).
We use #teamchannel to communicate inside the team.

The question is: how can I send some short message from example.com to #teamchannel from the bash script? e.g. example.com: Alert! The server is rebooting now

Edit:

I have found a perl script which does exactly what I needed.

takeshin
  • 1,431
  • 3
  • 19
  • 28
  • 1
    Link to perl script https://web.archive.org/web/20100125223219/http://www.javalinux.it/wordpress/2009/10/15/writing-an-irc-bot-for-svn-commit-notification/ – epatel Oct 17 '15 at 19:19

5 Answers5

12

IRC is a simple text and line oriented protocol, so it can be done with the basic linux tools. So, without installing ii:

echo -e 'USER bot guest tolmoon tolsun\nNICK bot\nJOIN #channel\nPRIVMSG #channel :Ahoj lidi!\nQUIT\n' \
| nc irc.freenode.net 6667

In this command, nc does the network connection, and you send a login info, nick, join a channel named "#channel" amd send a message "Ahoj lidi!" to that channel. And quit the server.

Ondra Žižka
  • 424
  • 2
  • 5
  • 14
9

use console irc client

apt-get install ii
ii -i /tmp -s 192.168.1.2
echo "/PRIVMSG #teamchannel example.com: Alert! The server is rebooting now" > /tmp/irc/in
bindbn
  • 5,153
  • 2
  • 26
  • 23
  • Thanks, but this does not work for me. After `ii` the shell waits, when I end the command with `&`, the second command executes but without message. – takeshin Sep 21 '10 at 13:50
  • red the 'out' file to debug problem: find irc directory(/tmp/SERVERNAME),cd /tmp/SERVERNAME and cat out,then echo message and read out. – bindbn Sep 21 '10 at 20:49
2

One solution would be to use expect to script communication with the IRC server using a telnet client.

Crankyadmin
  • 332
  • 1
  • 5
1
#!/bin/bash
exec 3>/dev/tcp/example.com/6667
echo "NICK nickname1234" >&3
echo "USER nickname1234 8 * : nickname1234" >&3
echo "JOIN #teamchannel" >&3
echo "PRIVMSG #teamchannel Alert!" >&3
echo "QUIT" >&3
cat <&3
atsa
  • 61
  • 3
1

If you need to supply a password and use ssl you can do something like this.

#!/bin/bash -e

USER=$1
MYPASSWORD=$2
IRC_SERVER=$3
IRC_PORT=$4
CHANNEL=$5
MSG=$6

(
echo NICK $USER
echo USER $USER 8 * : $USER
sleep 1
echo PASS $USER:$MYPASSWORD
echo "JOIN $CHANNEL"
echo "PRIVMSG $CHANNEL" $MSG
echo QUIT
) | ncat --ssl $IRC_SERVER $IRC_PORT

The script should be run like this:

./post_to_irc.sh your_user your_pass irc_server 6667 "#target-channel" "Your message"

This is similar to an earlier example using nc but I found I had to use ncat to get it working with our IRC server which has been set up with SSL.

Kevin Cross
  • 341
  • 2
  • 3