[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

RE: kickstart monitor



As requested.  

Here is what I have so far.  Please note that this is the first python program I
have ever written (I prefer perl and awk, but ks does not include in install
image), I am open to any suggestions if there are better methods.  I have only
tested RH9.  I hacked this together using the Python Cookbook as a guide.  It
needs work, but it is a start.

I have cut/paste 3 text files.

1.  The pre script.  This script creates a python file and runs it in the
background.  It listens on port 3001 for stat or sh ..., if stat then it will
dump the last line of install.log if it exists, if sh ..., then it will run ...
and return the output (a poor mans remote shell).
2.  nodestat.awk, is a simple example of a client to get the stat.
3.  nodecmd.awk, is a simple example of a client to run a remote command.

###pre script
%pre

cat >/tmp/foo.py <<EOF
#!/usr/bin/python

import socket
import os
import linecache
import re

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

port = 3001
sock.bind(('', port))

sock.listen(5)

try:
	while 1:
		newSocket, address = sock.accept()
		while 1:
			received = newSocket.recv(200)
			if not received:
				break
			command = re.split('\s+',received)
			if(command[0] == "stat"):
				ilog = ""
				line = ""
	
if(os.path.isfile('/mnt/sysimage/root/install.log')):
					ilog = '/mnt/sysimage/root/install.log'
	
if(os.path.isfile('/mnt/sysimage/tmp/install.log')):
					ilog = '/mnt/sysimage/tmp/install.log'
				if(ilog):
					count = len(open(ilog).readlines())
					line = linecache.getline(ilog,count)
					linecache.clearcache()
				if(line):
					r = re.compile("^Installing (.*)\.")
					m = r.search(line)
					if m:
						newline = m.group(1)
					else:
						newline = "prep"
					line = "installing " + newline
				else:
					line = "installing prep"
				newSocket.send(line)
				break
			if(command[0] == "sh"):
				newcommand = ""
				for i in command[1:]:
					newcommand = newcommand + i + " "
				output = os.popen(newcommand).read()
				newSocket.send(output)
				break
				
		newSocket.close()

finally:
	sock.close()
EOF

chmod 755 /tmp/foo.py

/tmp/foo.py >/foo.log 2>&1 &
###pre script end

###nodestat.awk
#!/bin/awk -f

BEGIN {
	node = ARGV[1]

	ns = "/inet/tcp/0/" node "/" 3001

	print "stat" |& ns

	while((ns |& getline) > 0)
		print $0

	close(ns)

	exit 0
}
###nodestat.awk end

###nodecmd.awk
#!/bin/awk -f

BEGIN {
	node = ARGV[1]

	for(i in ARGV)
		if(i > 1)
			command = (command " " ARGV[i])

	ns = "/inet/tcp/0/" node "/" 3001

	print ("sh" command)|& ns

	while((ns |& getline) > 0)
		print $0

	close(ns)

	exit 0
}
###nodecmd.awk end


> -----Original Message-----
> From: kickstart-list-admin redhat com 
> [mailto:kickstart-list-admin redhat com] On Behalf Of 
> James_Martin ao uscourts gov
> Sent: Wednesday, October 15, 2003 7:40 AM
> To: kickstart-list redhat com
> Subject: Re: kickstart monitor
> 
> 
> I was just wondering if you could provide a link to yoru 
> daemon when you 
> are finished-- it would be a very useful utility.
> 
> Thanks,
> 
> James
> 
> James S. Martin, RHCE
> Contractor
> Administrative Office of the United States Courts
> Washington, DC
> (202) 502-2394
> 
> 
> 
> 
> "Egan Ford" <egan sense net>
> Sent by: kickstart-list-admin redhat com
> 10/14/2003 06:02 PM
> Please respond to kickstart-list
> 
>  
>         To:     <kickstart-list redhat com>
>         cc: 
>         Subject:        kickstart monitor
> 
> 
> I am creating a small python daemon that gets starting in 
> %pre to allow 
> remote
> access to a node during install.  The purpose is to monitor the 
> installation of
> a large number of machines in a more automated fashion.
> 
> Are they any files that I can tail to get the status of the 
> installation?
> 
> Thanks.
> 
> 
> _______________________________________________
> Kickstart-list mailing list
> Kickstart-list redhat com
> https://www.redhat.com/mailman/listinfo/kickstart-list
> 
> 
> 
> 
> _______________________________________________
> Kickstart-list mailing list
> Kickstart-list redhat com
> https://www.redhat.com/mailman/listinfo/kickstart-list
> 




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]