approach to writing functions

Bart Nessux bart_nessux at
Tue Feb 10 14:44:56 CET 2004

Paul Prescod wrote:
> If I were you I would post one of these scripts and see if the function 
> and OO fans can make it easier to read or maintain by using structured 
> programming.

OK, here is a script that works w/o OO or functions. It's very useful... 
never fails. It helps sys admins track machines that have mobile users 
who are using DHCP.

# Tested on Linux Machines
# Run as cron as root
# May work on OS X too
# Dec 29, 2003 works on Mac OSX 10.3 like this:
# chown 'root' && chgrp 'wheel' && chmod '755'
# place in /usr/bin

from email.MIMEText import MIMEText
import smtplib
import os

u = "User"		#Change This to user's name.
f = "admin at"
t = "admin at"

fp0 = os.popen("/sbin/ifconfig en0 inet", "r")
fp1 = os.popen("/usr/bin/uptime", "r")
fp2 = os.popen("/usr/bin/uname -a", "r")
fp3 = os.popen("/usr/bin/wc -l /etc/passwd", "r")
msg = MIMEText("-- IFCONFIG --\n\n" + + "\n-- UPTIME --\n\n" 
+ + "\n-- UNAME --\n\n" + + "\n-- PASSWD LC 
--\n\n" +

msg["Subject"] = "%s's ifconfig Report" % u
msg["From"] = f
msg["To"] = t

h = ""
s = smtplib.SMTP(h)
s.sendmail(f, t, msg.as_string())

More information about the Python-list mailing list