[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

[off-topic] IRC Notifications In Shell Script

Fedora-Arm Mailing List Monitor Bot

So I couldn’t find a reasonable way to manage the amount of mailing list email being sent to my personal and school address so I had to do this. I know you’re probably tired of seeing my various IRC bot scripts but I couldn’t take the amount of email that the mailing list generates. This is a bot which monitors the fedora-arm mailing list and posts any new changes to a given channel. Right now its being tested in the #seneca-cdot-arm channel on the freenode network.

Edit: Last updated on June 30, 2011

mbot.py

import os
import re
import sys
import time

import lbot


def fechfile(filename, urlnstri=""):
	resllist = []
	
	try:
		fileobjc = file("/tmp/%s" % (filename))
		readdata = fileobjc.read()
		fileobjc.close()
	
	except:
		return resllist
	
	readdata = readdata.strip().lower()
	readdata = readdata.replace("\t", "").replace("\r", "").replace("\n", "")
	readdata = readdata.replace("<li>", "\n<li>")
	readdata = readdata.replace("</i>", "</i>\n")
	
	readlist = readdata.split("\n")
	
	for readitem in readlist:
		readitem = readitem.strip()
		
		regxobjc = re.match('^<li><a href="([^"]+)">(.+)</a><a name="[^"]+">[^<]+</a><i>([^<]+)</i>$', readitem)
		
		if (regxobjc):
			reslstri = ("[%s] [%s] [ %s ]" % (regxobjc.group(3), regxobjc.group(2), urlnstri + regxobjc.group(1)))
			resllist.append(reslstri)
	
	return resllist

def ircbmain():
	if (len(sys.argv) < 4):
		print("Usage: %s <nick> - <chan 0> ... <chan N>" % (sys.argv[0]))
		sys.exit(0)
	
	nickname = ""
	chanlist = []
	
	x = 1
	l = len(sys.argv)
	f = 0
	
	while (x < l):
		if (sys.argv[x] == "-"):
			f += 1
		
		elif (f == 0):
			nickname = sys.argv[x]
		
		elif (f == 1):
			chanlist.append(sys.argv[x])
		
		x += 1
	
	websstri = ("http://lists.fedoraproject.org/pipermail/arm/%s-%s/" % (time.strftime("%Y"), time.strftime("%B")))
	
	p = os.fork()
	
	if (p == 0):
		websstri = ("%sdate.html" % (websstri))
		
		lbot.readurls(urlnlist=[websstri], filename=nickname)
		sys.exit(0)
	
	pastdata = []
	presdata = []
	
	lbot.ircbinit(nickname, chanlist)
	
	while (1):
		tempdata = fechfile(nickname, urlnstri=websstri)
		
		if (tempdata):
			presdata = tempdata
			
			if (not pastdata):
				pastdata = presdata
		
		ircdstri = lbot.ircbmain(pastdata, presdata)
		
		if (type(ircdstri) == type(-1)):
			break
		
		if (presdata):
			pastdata = presdata

ircbmain()

Fedora-Arm Mailing List Monitor Bot

Message Highlighting Bot

This py bot script will join all of the channels given to it and sit there monitoring for messages containing any keywords provided to it. It will then forward those messages along to a given nick.

Edit: Last updated on June 30, 2011

pbot.py

import os
import re
import sys
import time

import lbot

def ircbmain():
	print(sys.argv)
	if (len(sys.argv) < 8):
		print("Usage: %s <nick> - <chan 0> ... <chan N> - <dest> - <srch 0> ... <srch N>" % (sys.argv[0]))
		sys.exit(0)
	
	nickname = ""
	chanlist = []
	destname = ""
	srchlist = []
	
	x = 1
	l = len(sys.argv)
	f = 0
	
	while (x < l):
		if (sys.argv[x] == "-"):
			f += 1
		
		elif (f == 0):
			nickname = sys.argv[x]
		
		elif (f == 1):
			chanlist.append(sys.argv[x])
		
		elif (f == 2):
			destname = sys.argv[x]
		
		elif (f == 3):
			srchlist.append(sys.argv[x])
		
		x += 1
	
	lbot.ircbinit(nickname, chanlist)
	
	while (1):
		ircdstri = lbot.ircbmain([], [])
		
		for srchstri in srchlist:
			regxobjc = re.match("^:?([^ ]+)![^ ]+ PRIVMSG ([^ ]+) :(.*%s.*)" % (srchstri), ircdstri, re.I)
			
			if (regxobjc):
				mesgstri = ("PRIVMSG %s :mesg detect: [%s] in [%s] mesg [ %s ]" % (destname, regxobjc.group(1), regxobjc.group(2), regxobjc.group(3)))
				lbot.waitsend(mesgstri)
				break
			
			regxobjc = re.match("^:?([^ ]*%s[^ ]*)![^ ]+ PRIVMSG ([^ ]+) :(.+)" % (srchstri), ircdstri, re.I)
			
			if (regxobjc):
				mesgstri = ("PRIVMSG %s :nick detect: [%s] in [%s] mesg [ %s ]" % (destname, regxobjc.group(1), regxobjc.group(2), regxobjc.group(3)))
				lbot.waitsend(mesgstri)
				break

ircbmain()

Message Highlighting Bot

reddit/slashdot RSS IRC Bot

Just wanted to separate the below post a bit and I pulled this bot script out to do so. It simply grabs the RSS feed from the given list of URLs and posts any changes to a given channel.

rbot.py

import os
import re
import select
import urllib
import sys
import time

import lbot

def fechwebs():
	readdata = ""
	urlnlist = ["www.reddit.com/.rss", "rss.slashdot.org/Slashdot/slashdot"]
	resllist = []
	
	xmlshead = ""
	xmlslink = ""
	
	for urlnitem in urlnlist:
		uobjdata = urllib.urlopen("http://" + urlnitem)
		readdata += uobjdata.read()
	
	readdata = readdata.replace("\r", "")
	readdata = readdata.replace("\n", "")
	readdata = readdata.replace("<", "\n<")
	
	datalist = readdata.split("\n")
	
	for dataitem in datalist:
		regxobjc = re.match("<title>(.*)", dataitem)
		
		if (regxobjc):
			xmlshead = ("[" + regxobjc.group(1) + "]")
		
		regxobjc = re.match("<link>(.*)", dataitem)
		
		if (regxobjc):
			xmlslink = regxobjc.group(1)
		
		if ((xmlshead != "") and (xmlslink != "")):
			resllist.append(xmlshead + " " + xmlslink)
			
			xmlshead = ""
			xmlslink = ""
	
	if (len(resllist) == 0):
		return -1
	
	return resllist

def ircbmain():
	if (len(sys.argv) < 4):
		print("Usage: %s <nick> - <chan 0> ... <chan n>" % (sys.argv[0]))
		sys.exit(0)
	
	nickname = ""
	chanlist = []
	
	x = 1
	l = len(sys.argv)
	f = 0
	
	while (x < l):
		if (sys.argv[x] == "-"):
			f += 1
		elif (f == 0):
			nickname = sys.argv[x]
		elif (f == 1):
			chanlist.append(sys.argv[x])
		x += 1
	
	webstime = 0
	webswait = (5 * 60)
	pastdata = -1
	presdata = -1
	
	lbot.ircbinit(nickname, chanlist)
	
	while (1):
		prestime = time.time()
		difftime = (prestime - webstime)
		
		if (difftime > webswait):
			print(lbot.formtime() + " WEB [INFO] Checking site(s)...")
			presdata = fechwebs()
			
			if (type(pastdata) == type(-1)):
				pastdata = presdata
			
			webstime = prestime
		
		ircdstri = lbot.ircbmain(pastdata, presdata)
		
		if (type(ircdstri) == type(-1)):
			break
		
		if (type(presdata) != type(-1)):
			pastdata = presdata

ircbmain()

reddit/slashdot RSS IRC Bot

Checking JavaScript Variables With Python

So I have OCD when it comes to JavaScript because it’s such a lenient language and it is hard to tell when you’re misusing variables. The editors that I use on a daily basis don’t tell me if (1) a variable has been declared but never used and (2) if a variable is being used without having been declared. I wrote a python script which attempts to check for these cases. There may be a bunch of bugs as I did not write a JavaScript language parser but instead a series of checks based on regex. Here is the code:

Edit: One of the commenter’s pointed out that one could use jslint and jshint to receive way better information about your JS code. Thank you for the recommendation!

#!/usr/bin/python

import re
import sys

def rmescape(inptstri):
	backflag = 0
	outpstri = ""
	
	for letritem in inptstri:
		if (letritem == '\\'):
			backflag = 1
		
		elif (backflag == 1):
			backflag = 0
		
		else:
			outpstri += letritem
	
	return outpstri

scptflag = 0
readlist = []

while (1):
	tempread = sys.stdin.readline()
	
	if (not tempread):
		break
	
	# clean the front and end of the string
	tempread = tempread.strip()
	
	if (re.match("^</script.*$", tempread)):
		scptflag = 0
	
	if (scptflag == 1):
		templist = tempread.split(";")
		
		for tempitem in templist:
			if (tempitem not in readlist):
				readlist.append(tempitem)
	
	if (re.match("^<script.*$", tempread)):
		scptflag = 1

varslist = []

for lineread in readlist:
	# remove any escapes
	lineread = rmescape(lineread)
	
	# remove any chars, strings, regex
	lineread = re.sub("\'[^\']*\'", "", lineread)
	lineread = re.sub("\"[^\"]*\"", "", lineread)
	lineread = re.sub("\/[^\/]+\/", "", lineread)
	
	# remove any comments
	lineread = re.sub("//.*", "", lineread)
	
	# remove any lists, arrays, dictionaries
	lineread = re.sub("\<[^\>]*\>", "", lineread)
	lineread = re.sub("\[[^\]]*\]", "", lineread)
	lineread = re.sub("\{[^\}]*\}", "", lineread)
	#lineread = re.sub("\([^\)]*\)", "", lineread)
	
	tempstri = ""
	
	regxobjc = re.match("^var[ ]+(.*)$", lineread)
	
	if (regxobjc):
		tempstri = regxobjc.group(1)
	
	regxobjc = re.match("^function[ ]+(.*)$", lineread)
	
	if (regxobjc):
		tempstri = regxobjc.group(1)
		tempstri = tempstri.replace("(", ",")
		tempstri = tempstri.replace(")", "")
	
	if (tempstri != ""):
		# remove any spaces, tabs
		tempstri = tempstri.replace(" ", "")
		tempstri = tempstri.replace("\t", "")
		
		# remove any variable assignment values
		tempstri = re.sub("=[^,]*", "", tempstri)
		
		# split the line to get all of the decalred variables
		templist = tempstri.split(",")
		
		for tempitem in templist:
			if (tempitem not in varslist):
				varslist.append(tempitem)

#print(varslist)

for varsread in varslist:
	usedflag = 0
	
	for lineread in readlist:
		# remove any spaces, tabs
		lineread = lineread.replace(" ", "")
		lineread = lineread.replace("\t", "")
		
		# skip variable assignment lines
		regxobjc = re.match("^.*" + varsread + "=[^=].*$", lineread)
		
		if (regxobjc):
			continue
		
		# get variable usage lines
		regxobjc = re.match("^.*" + varsread + ".*$", lineread)
		
		if (regxobjc):
			usedflag = 1
			break
	
	if (usedflag == 0):
		print("note: variable possibly unused: [%s]" % (varsread))

nameregx = "[A-Za-z][0-9A-Za-z\_]*"
templist = ["null", "true", "false", "document", "window", "Math"]

for tempitem in templist:
	varslist.append(tempitem)

for lineread in readlist:
	origline = lineread
	
	# replace any variable declaration prefix's
	lineread = re.sub("^var ", "", lineread)
	
	# replace any function declaration lines
	lineread = re.sub("^function .*", "", lineread)
	
	# replace any return statement lines
	lineread = re.sub("^return .*", "", lineread)
	
	# remove any spaces, tabs
	lineread = lineread.replace(" ", "")
	lineread = lineread.replace("\t", "")
	
	# remove any chars, strings, regex
	lineread = re.sub("\'[^\']*\'", "", lineread)
	lineread = re.sub("\"[^\"]*\"", "", lineread)
	lineread = re.sub("\/[^\/]+\/", "", lineread)
	
	# remove any comments
	lineread = re.sub("//.*", "", lineread)
	
	# replace any method calls (special replace char to prevent function replace)
	lineread = re.sub("\." + nameregx + "[=\(]*", "~", lineread)
	
	# replace any assignments, function calls
	lineread = re.sub(nameregx + "[=\(]", "", lineread)
	
	while (1):
		regxobjc = re.search("(" + nameregx + ")", lineread)
		
		if (not regxobjc):
			break
		
		namestri = regxobjc.group(1)
		
		if (namestri not in varslist):
			print("warn: variable possibly undeclared: [%s] on line [%s]" % (namestri, origline))
		
		lineread = lineread.replace(namestri, "")

Checking JavaScript Variables With Python

Convert Text To HTML Char Codes

I got tired of hand-formatting or shell-scripting a text converter for this blog to post code properly so I wrote this py script to do it for me. It converts a text file containing possibly used HTML characters into HTML character codes.

#!/usr/bin/python
import sys
s = ""
l = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
while (1):
	c = sys.stdin.read(1)
	if (not c):
		break
	o = ord(c)
	if (o == 13):
		continue
	elif ((o < 127) and (c not in l)):
		s += ("&#" + str(o) + ";")
	else:
		s += (c)
print(s)

Convert Text To HTML Char Codes

Non-Exiting Screen Startup

I was trying to run screen in the background with a python script inside of it, however, when the python was exiting due to coding errors, the screen was quitting too. I could have turned on logging but I didn’t want to deal with screen log files all the time. I wanted the screen session to remain open, even if the python quit so I could reattach to it and see what was going on (like a normal command prompt). Here was the solution I came up with:

/usr/bin/screen -dm /bin/bash -c 'echo "your program here" ; /bin/bash'

Run this to reattach it later:

/usr/bin/screen -dr
Non-Exiting Screen Startup

JavaScript Popup For The CDoT Dashboard

Below is a simple piece of JavaScript which will open a new pop-up window pointing to the CDoT dashboard that contains various interesting stats related to our work. You are able to change the height and width of the window by modifying the appropriate options below. In addition, you are able to disable features like the toolbar, menubar and statusbar in order to give the window a fullscreen-kiosk-like look and feel.

<script type="text/javascript">
	window.open("http://scotland.proximity.on.ca/jbuck/status/", "awesome", "width=1700, height=1900, \
toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no");
</script>
JavaScript Popup For The CDoT Dashboard

Simple RSS Application For OS X

Here’s an application I created for OS X which grabs new stories/articles that are posted to slashdot and reddit front pages (you can’t enter any site yet but it works with RSS). The app is meant to be run off focus (behind other windows) and it will keep a list of stories read in order to tell which stories are new. As you click on the new stories you want to read, they will disappear and once the window is put in the background, it will open the chosen articles in the default browser and remove the new stories from the list.

I created this app as it acts more like an RSS-diff program and simply tracks and monitors changes in RSS stories. The busier the feed the better as this program will basically keep a log of stories until you check them out. Let me know if you find this program useful and/or have any suggestions on how to make it better!

Feed App Download [via mediafire]

Simple RSS Application For OS X

Smarter Fedora Build Process (Styrene)

This project will hopefully allow for a smarter build process to take place when building Fedora which includes choosing a specific order for the packages destined to be queued. It should allow one to intelligently determine which packages need to be built first (if it has 0 dependencies or all of its dependencies already built). The main loop basically just performs passes through the list of unbuilt packages and seeing which ones meet these requirements and queuing them.



[replaced by a new script: koji-follow.py]

Smarter Fedora Build Process (Styrene)

Automatically Move Files From One Dir To Another

Here is a lame script that you can run in the background to automatically pick up files in one user’s home directory and place them on your desktop. Just run this as root and it will check to see if the user is no longer logged in first and if so, it takes ownership of any file found and moves it to your desktop.

#!/bin/bash

if [ "$2" == "" ]
then
	echo "Usage: $0 <source username> <destination username>"
	exit 1
fi

while true
do
	testoutp=`who | grep -i "$1"`
	if [ "$testoutp" == "" ]
	then
		find /home/$1 -type f -exec chown "$2:$2" "{}" \;
		find /home/$1 -type f -exec mv "{}" "/home/$2/Desktop/tmp/" \;
	fi
	sleep 5
done

Automatically Move Files From One Dir To Another

A CDoT Python IRC Bot

Below is a basic IRC bot written in python which grabs the builder bot statuses from the arm.koji website and sends a message to a channel if the enable or ready statuses change to “no”. The lbot.py code is a shared python library/module and various python bot scripts can use this module to achieve different tasks for IRC messaging/action.

Edit: Last updated on June 30, 2011

lbot.py

import os
import re
import signal
import select
import socket
import sys
import time
import urllib


def formtime():
	currsecs = time.localtime()
	
	return time.strftime("%H:%M:%S", currsecs)

def fakehand(s, f):
	pass

def readurls(urlnlist=[], filename="lbot.txt"):
	waittime = (5 * 60)
	
	while (1):
		outpstri = ""
		
		for urlnitem in urlnlist:
			signal.signal(signal.SIGALRM, fakehand)
			signal.alarm(waittime / 2)
			
			try:
				uobjdata = urllib.urlopen(urlnitem)
				tempstri = uobjdata.read()
				print("fetched [%d] bytes from [%s]" % (len(tempstri), urlnitem))
			
			except:
				outpstri = ""
				break
			
			outpstri += tempstri
			signal.alarm(0)
		
		if (outpstri):
			fileobjc = open("/tmp/%s" % (filename), "w")
			fileobjc.write(outpstri)
			fileobjc.close()
		
		time.sleep(waittime)

sockline_s = {}

def sockline(sockpref, sockobjc):
	global sockline_s
	
	if (not sockpref in sockline_s.keys()):
		sockline_s[sockpref] = ""
	
	timeread = 0.25
	chekstri = sockline_s[sockpref].find("\n")
	
	while (chekstri == -1):
		(readlist, sendlist, errolist) = select.select([sockobjc], [], [], timeread)
		
		if (sockobjc in readlist):
			tempread = sockobjc.recv(1024)
			
			if (len(tempread) == 0):
				print("socket error...")
				sys.exit(0)
			
			sockline_s[sockpref] += tempread
			chekstri = sockline_s[sockpref].find("\n")
		
		else:
			break
	
	chekstri += 1
	reslstri = sockline_s[sockpref][:chekstri]
	sockline_s[sockpref] = sockline_s[sockpref][chekstri:]
	
	if ((len(reslstri) > 0) and (sockpref != "")):
		outpstri = ("%s %s [RECV] %s" % (formtime(), sockpref, reslstri.strip()))
		print(outpstri)
	
	return reslstri

sockobjc = None

def socksend(sockpref, sendstri):
	global sockobjc
	
	tempstri = sendstri.strip()
	
	if ((len(tempstri) > 0) and (sockpref != "")):
		outpstri = ("%s %s [SEND] %s" % (formtime(), sockpref, tempstri))
		print(outpstri)
	
	sockobjc.send(sendstri + "\r\n")

sendtime = 0
sendwait = 1
sockpref = "IRC"
sendlist = []

def waitsend(sendstri=""):
	global sockobjc
	
	global sendtime
	global sendwait
	global sockpref
	global sendlist
	
	if (sendstri != ""):
		sendlist.append(sendstri)
	
	if (len(sendlist) > 0):
		prestime = time.time()
		difftime = (prestime - sendtime)
		
		if (difftime >= sendwait):
			socksend(sockpref, sendlist[0])
			sendlist.pop(0)
			sendtime = prestime

nickname = ""
chanblst = []

def ircbinit(nickstri, chanlist):
	global sockobjc
	global sockpref
	
	global nickname
	global chanblst
	
	hostname = "irc.freenode.net"
	hostport = 6667
	
	idenname = "alex"
	fillname = "bob"
	realname = "charlie"
	
	nickname = nickstri
	chanblst = chanlist
	
	sockobjc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	sockobjc.connect((hostname, hostport))
	
	socksend(sockpref, "NICK %s" % (nickname))
	socksend(sockpref, "USER %s %s %s :%s" % (idenname, hostname, fillname, realname))

jointime = 0
joinwait = (5 * 60)

def ircbmain(pastdata, presdata):
	global sockpref
	global sockobjc
	
	global nickname
	global chanblst
	
	global jointime
	global joinwait
	
	# check for a valid socket object first
	
	if (sockobjc == None):
		print("null error...")
		return -1
	
	# set some shared method vars
	
	prestime = time.time()
	
	# read a line from the socket object and exit if error
	
	readdata = sockline(sockpref, sockobjc)
	waitsend()
	
	if (type(readdata) == type(-1)):
		sockobjc.close()
		print("socket error...")
		return -2
	
	readdata = readdata.strip()
	
	# if server ping the send pong back
	
	chekstri = readdata.find("PING :")
	
	if (chekstri == 0):
		chekstri = readdata.find(":")
		sendstri = ("PONG %s" % (readdata[chekstri:]))
		
		socksend(sockpref, sendstri)
		readdata = ""
	
	# delay send the join channel commands if connect or time
	
	chekstri = readdata.find("001 %s" % (nickname))
	difftime = (prestime - jointime)
	
	if ((chekstri != -1) or ((jointime != 0) and (difftime > joinwait))):
		for channame in chanblst:
			sendstri = ("JOIN %s" % (channame))
			waitsend(sendstri)
		
		jointime = prestime
		readdata = ""
	
	# check to see if we successfuly joined at least one channel
	
	regxobjc = re.match("^:?%s[^ ]* JOIN :.*" % (nickname), readdata)
	
	if (regxobjc):
		jointime = prestime
		readdata = ""
	
	# if we have not joined a channel yet then return
	
	if ((jointime == 0) or (not pastdata) or (not presdata)):
		return readdata
	
	# if list size was requested then send the length of the list
	
	regxobjc = re.match("^:?[^ ]* PRIVMSG ([^ ]*) :%s numb.*" % (nickname), readdata)
	
	if (regxobjc):
		sendstri = ("PRIVMSG %s :[#] %d" % (regxobjc.group(1), len(presdata)))
		socksend(sockpref, sendstri)
	
	# if a list tail was requested then send the specified number of items
	
	regxobjc = re.match("^:?[^ ]* PRIVMSG ([^ ]*) :%s tail(.*)" % (nickname), readdata)
	
	if (regxobjc):
		try:
			tailnumb = regxobjc.group(2).strip()
			tailnumb = (-1 * int(tailnumb))
		
		except:
			tailnumb = -1
		
		for presitem in presdata[tailnumb:]:
			sendstri = ("PRIVMSG %s :[*] %s" % (regxobjc.group(1), presitem))
			waitsend(sendstri)
	
	# print out any list diffs
	
	for presitem in presdata:
		if (presitem in pastdata):
			continue
		
		for channame in chanblst:
			sendstri = ("PRIVMSG %s :[+] %s" % (channame, presitem))
			waitsend(sendstri)
	
	return readdata

sbot.py

import os
import re
import sys
import time

import lbot

def fechfile(filename, urlnstri=""):
	resllist = []
	
	try:
		fileobjc = file("/tmp/%s" % (filename))
		readdata = fileobjc.read()
		fileobjc.close()
	
	except:
		return resllist
	
	readdata = readdata.replace("\t", "").replace("\r", "").replace("\n", "")
	readdata = readdata.replace("<tr", "\n<tr")
	readlist = readdata.split("\n")
	
	for readitem in readlist:
		regxobjc = re.match(".*<a href=\"hostinfo\?hostID=[0-9]*\">([^<]*cdot[^<]*)</a>.*<td>([0-9]+)-([0-9]+)-([0-9]+) ([0-9]+):([0-9]+):([0-9]+)</td>.*", readitem)
		
		if (not regxobjc):
			continue
		
		hostname = regxobjc.group(1)
		edthour = (int(regxobjc.group(5)) - 4)
		
		edthour = str(edthour)
		checkind = int(regxobjc.group(2) + regxobjc.group(3) + regxobjc.group(4) + regxobjc.group(5) + regxobjc.group(6))
		timesecs = (time.time() + (4 * 60 * 60) - (30 * 60))
		locltime = time.localtime(timesecs)
		presdate = int(time.strftime("%Y%m%d%H%M", locltime))
		
		if (checkind < presdate):
			hoststri = ("[%s] last check-in [%s-%s-%s %s:%s:%s]" % (hostname, regxobjc.group(2), regxobjc.group(3), regxobjc.group(4), edthour, regxobjc.group(6), regxobjc.group(7)))
			resllist.append(hoststri)
	
	return resllist

def ircbmain():
	if (len(sys.argv) < 4):
		print("Usage: %s <nick> - <chan 0> ... <chan N>" % (sys.argv[0]))
		sys.exit(0)
	
	nickname = ""
	chanlist = []
	
	x = 1
	l = len(sys.argv)
	f = 0
	
	while (x < l):
		if (sys.argv[x] == "-"):
			f += 1
		
		elif (f == 0):
			nickname = sys.argv[x]
		
		elif (f == 1):
			chanlist.append(sys.argv[x])
		
		x += 1
	
	p = os.fork()
	
	if (p == 0):
		templist = []
		
		for x in range(0, 3):
			templist.append("http://arm.koji.fedoraproject.org/koji/hosts?state=all&order=name&start=%d" % (x * 50))
		
		lbot.readurls(urlnlist=templist, filename=nickname)
		sys.exit(0)
	
	pastdata = []
	presdata = []
	
	lbot.ircbinit(nickname, chanlist)
	
	while (1):
		tempdata = fechfile(nickname)
		
		if (tempdata):
			presdata = tempdata
			
			if (not pastdata):
				pastdata = presdata
		
		ircdstri = lbot.ircbmain(pastdata, presdata)
		
		if (type(ircdstri) == type(-1)):
			break
		
		if (presdata):
			pastdata = presdata

ircbmain()

A CDoT Python IRC Bot

Sending An SSH Key To Multiple SSH Hosts

The script below will first create an SSH public/private key pair on the current, main host. It will then get your username and prompt for your password allowing the root user to add your account to the destination servers. Note: you must have a root login on each host. The ping statement is used to check to see if the host is up so we don’t waste time. This script will then wait on stdin (via cat with no arguments) and write the ssh key-file (via the piped data) to the temp directory. It will then add the username, set the password, create a ssh directory and move the transferred key file to it. At the end, it will then give ownership to the specified username.

#!/bin/bash

ssh-keygen

u=`whoami`
read -s -p "Password: " pass

for x in {1..7}-{1..5}
do
	ping -c 1 -W 1 $x > /dev/null 2>&1
	if [ $? -eq 0 ]
	then
		tempkeyf='cat > /tmp/authorized_keys'
		makeuser='useradd '$u
		makepass='printf "'$pass'" | passwd --stdin '$u
		makesshd='mkdir /home/'$u'/.ssh'
		copykeyf='mv /tmp/authorized_keys /home/'$u'/.ssh/'
		ownevery='chown -R '$u' /home/'$u'/.ssh'
		cat ~/.ssh/id_rsa.pub | ssh root@$x "$tempkeyf ; $makeuser ; $makepass ; $makesshd ; $copykeyf ; $ownevery"
	fi
done

Sending An SSH Key To Multiple SSH Hosts