Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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


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

share|improve this question
Link to perl script… – epatel Oct 17 '15 at 19:19
up vote 7 down vote accepted

use console irc client

apt-get install ii
ii -i /tmp -s
echo "/PRIVMSG #teamchannel Alert! The server is rebooting now" > /tmp/irc/in
share|improve this answer
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

Without installing ii:

echo -e 'USER bot guest tolmoon tolsun\nNICK bot\nJOIN #channel\nPRIVMSG #channel :Ahoj lidi!\nQUIT\n' \
| nc 6667
share|improve this answer
add \nQUIT at the end of the list of commands to quit right after sending the one message – Walter Heck Dec 23 '11 at 10:10

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

share|improve this answer
Do I need expect when I want to send the message from the same machine where the IRC server is installed? – takeshin Sep 21 '10 at 13:24
you do.. the above solution would work well with expect. – Crankyadmin Sep 21 '10 at 14:22
exec 3>/dev/tcp/
echo "NICK nickname1234" >&3
echo "USER nickname1234 8 * : nickname1234" >&3
echo "JOIN #teamchannel" >&3
echo "PRIVMSG #teamchannel Alert!" >&3
echo "QUIT" >&3
cat <&3
share|improve this answer
A bit of text around the shell script would go a long way to making this a better answer. – HBruijn Oct 24 '14 at 20:08

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

#!/bin/bash -e


echo USER $USER 8 * : $USER
sleep 1
echo QUIT
) | ncat --ssl $IRC_SERVER $IRC_PORT

The script should be run like this:

./ 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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.