Skip to content

Instantly share code, notes, and snippets.

@noirscape
Created September 3, 2017 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noirscape/d7dd01f05d5493124c70b3aabf8070d7 to your computer and use it in GitHub Desktop.
Save noirscape/d7dd01f05d5493124c70b3aabf8070d7 to your computer and use it in GitHub Desktop.

A simple IRC log script

Just wget the file below, set the variables nick,channel and server and run it (config doesn't need to be changed). Output is send to stdout. You probably want to send it to a file. To do so, I recommend one of these structures:

If you don't want to see the output in a terminal:

irclogscript.sh >> logs.txt

If you do want to see the output in a terminal:

irclogscript.sh | tee -a logs.txt

Both of these commands are non-destructive; Data is always appended to the file.

The default nick is $$ which is the pID for the script when you run it.

Best run in a tmux window.

Original script taken from here

#!/bin/sh
nick="$$"
channel=
server=
config=/tmp/irclog
[ -n "$1" ] && channel=$1
[ -n "$2" ] && server=$2
config="${config}_${channel}"
now=$(date)
echo "Logging Started at $now" > $config
echo "NICK $nick" >> $config
echo "USER $nick +i * :$0" >> $config
echo "JOIN #$channel" >> $config
trap '"now2=$(date); echo "Logging ended at $now2" >> $config"' INT TERM EXIT
tail -f $config | nc $server 6667 | while read MESSAGE
do
case "$MESSAGE" in
PING*) echo "PONG${MESSAGE#PING}" >> $config;;
*QUIT*) ;;
*PART*) ;;
*JOIN*) ;;
*NICK*) ;;
*PRIVMSG*) echo "${MESSAGE}" | sed -nr "s/^:([^!]+).*PRIVMSG[^:]+:(.*)/[$(date '+%R')] \1> \2/p";;
*) echo "${MESSAGE}";;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment