[off-topic] IRC Notifications In Shell Script

So I haven’t had anything that I thought was important enough to blog about lately and I decided to take a break from in-depth python and make something random/weird. This is a shell script which runs in a loop to search for packets with certain text. Once that text is found, it executes a given command.

Example:

./irce.sh eth0 6667 'privmsg.*nickname' 'xeyes'

This example will monitor any IRC traffic for any message which contains the nickname given above and if so, it will execute the xeyes program to pop-up on your display.

#!/bin/bash

if [ "$4" == "" ]
then
	echo "Usage: $0 <interface> <port> <search regex> <command>"
	exit 0
fi

intf="$1"
port="$2"
srch="$3"
comd="$4"

tcpdump -Alnni "$intf" port "$port" 2> /dev/null | while read lineread
do
	testoutp=`echo "$lineread" | grep -i "$srch"`
	if [ "$testoutp" != "" ]
	then
		/bin/bash -c $comd &
	fi
done

Advertisements
[off-topic] IRC Notifications In Shell Script

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s