Copyright©2001O'Reilly&Associates,Inc.Allrightsreserved.
PerlforSystemAdministration
ByDavidN.Blank-Edelman
ISBN1-56592-609-9
Printbookcopyright©2000O'Reilly&Associates,Inc.Allrightsreserved.
PublishedbyO'Reilly&Associates,Inc.,101MorrisStreet,Sebastopol,CA
95472.
Thiselectronicpublicationisintendedforusebyoneindividual.Assuch,you
maymakecopiesforyourownpersonaluse.However,youmaynotprovide
copiestoothers,ormakethispublicationavailabletoothersoveraLANorother
network.Youmaynotreprint,offerforsale,orotherwisere-usematerialfrom
thispublicationwithouttheexplicitwrittenpermissionofO'Reilly&Associates,
Inc.
YoucanpurchaseprinteditionsofthesebooksdirectlyfromO'Reilly&
Associates,Inc.orfrombookstoresthatcarryO'Reilly&Associatesbooks.
LogosandTrademarks
TheO'ReillylogoisaregisteredtrademarkofO'Reilly&Associates,Inc.Many
ofthedesignationsusedbymanufacturersandsellerstodistinguishtheir
productsareclaimedastrademarks.Wherethosedesignationsappearinthis
book,andO'Reilly&Associates,Inc.wasawareofatrademarkclaim,the
designationshavebeenprintedincapsorinitialcaps.
Disclaimer
Whileeveryprecautionhasbeentakeninthepreparationofthisproduct,the
publisherassumesnoresponsibilityforerrorsoromissions,orfordamages
resultingfromtheuseoftheinformationcontainedherein.
Questions,comments,andsuggestionsto
Copyright©2001O'Reilly&Associates.Allrightsreserved.
Colophon
Ourlookistheresultofreadercomments,ourownexperimentation,and
feedbackfromdistributionchannels.Distinctivecoverscomplementour
distinctiveapproachtotechnicaltopics,breathingpersonalityandlifeinto
potentiallydrysubjects.
TheanimalonthecoverofPerlforSystemAdministrationisaseaotter.North
AmericanseaottersmaketheirhomesalongthePacificcoast,nearthekelpbeds
containingtheshellfishthatmakeupthemajorityoftheirdiet.Seaotterscanbe
foundingreatnumbersinAlaska,andonbeachesasfarsouthasCalifornia.
Seaottersareagileandintelligentmammals,andareknowntomakeingenious
useoftools.Floatingontheirbacks,theyholdashellfishsuchasamusselor
abaloneontheirbellies,andusearocktobreaktheshell.
Intenselysocial,seaottersgathertofloatingroupscalledrafts.Theyare
excellentswimmers,propellingthemselvesswiftlythroughthewaterwiththeir
flipper-like,webbedbackpaws.Theirthickfurprovidesthemwithefficient
insulationinthewater.Attimes,theirexistencehasbeenthreatenedastheyhave
beenmercilesslyhuntedtonearextinctionfortheirfur.
ColleenGormanwastheproductioneditorandcopyeditorforPerlforSystem
Administration.JaneEllinwastheproofreader.MarySheehanandEmilyQuill
providedqualitycontrol.MollyShangraw,MaeveO'Meara,GabeWeiss,Mary
Sheehan,andDarrenKellyprovidedproductionsupport.NancyCrumptonwrote
theindex.
HannaDyerdesignedthecoverofthisbook,basedonaseriesdesignbyEdie
Freedman.ThecoverimageisanoriginalillustrationcreatedbyLorrieLeJeune.
EmmaColbyproducedthecoverlayoutwithQuarkXPress3.32usingAdobe's
ITCGaramondfont.
AliciaCechandDavidFutatodesignedtheinteriorlayoutbasedonaseries
designbyNancyPriest.MikeSierraandDavidFutatoimplementedthedesign
inFrameMaker5.5.6.ThetextandheadingfontsareITCGaramondLightand
GaramondBook.Theillustrationsthatappearinthebookwereproducedby
RobertRomanoandRhonPorterusingMacromediaFreeHand8andAdobe
Photoshop5.ThiscolophonwaswrittenbyColleenGorman.
Copyright©2001O'Reilly&Associates.Allrightsreserved.
Symbols|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|
V|W|X|Y|Z
Index:Symbols
Therearenoindexentriesforthisletter.
Symbols|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|
V|W|X|Y|Z
Copyright©2001O'Reilly&Associates,Inc.AllRightsReserved.
Symbols|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|
V|W|X|Y|Z
Index:A
AccessControlList(ACL):2.2.2.MicrosoftWindowsNT/2000
accountcreation/deletion,programsfor
Unix:3.3.2.1.Unixaccountcreationanddeletionroutines
WindowsNT/2000:3.3.2.2.WindowsNT/2000accountcreationand
deletionroutines
accountsystems:3.3.1.TheBackendDatabase
building:3.3.BuildinganAccountSystemtoManageUsers
databases,usein:3.3.1.TheBackendDatabase
ActiveDirectory:6.5.ADSI(ActiveDirectoryServiceInterfaces)
ActiveDirectoryServiceInterfaces(seeADSI)
ActiveStaterepository:1.5.LocatingandInstallingModules
ActiveXDataObjects(seeADO)
adcomplainprogram:8.3.3.TrackingDownSpam
ADO(ActiveXDataObjects):6.5.6.Searching
ADSI(ActiveDirectoryServiceInterfaces):3.2.1.NT/2000UserIdentity
StorageandAccess
6.5.ADSI(ActiveDirectoryServiceInterfaces)
6.5.1.ADSIBasics
resourcesforusing:6.5.1.ADSIBasics
searchesin:6.5.6.Searching
systemadministrationwith:6.5.8.WorkingwithUsersviaADSI
usingfromPerl:6.5.2.UsingADSIfromPerl
ADSIDumpprogram:6.5.5.SoHowDoYouKnowAnythingAboutanObject?
ADsPaths:6.5.1.ADSIBasics
6.5.5.SoHowDoYouKnowAnythingAboutanObject?
6.5.7.PerformingCommonTasksUsingtheWinNTandLDAP
Namespaces
algorithm,message-digest:10.1.1.LocalFilesystemChanges
AmericanRegistryforInternetNumbers(ARIN):8.3.3.2.Checkingagainst
Internet-wideblacklists
APNIC(AsiaPacificAddressAllocations):8.3.3.2.CheckingagainstInternetwideblacklists
AppleEvents:8.1.2.UsingtheOS-SpecificIPCFramework.
AppleScript:8.1.2.UsingtheOS-SpecificIPCFramework.
8.1.2.UsingtheOS-SpecificIPCFramework.
@ARGV,retrievingunderMacOS:2.4.WalkingtheFilesystemUsingthe
File::FindModule
ARIN(AmericanRegistryforInternetNumbers):8.3.3.2.Checkingagainst
Internet-wideblacklists
AsiaPacificAddressAllocations(APNIC):8.3.3.2.CheckingagainstInternetwideblacklists
Symbols|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|
V|W|X|Y|Z
Copyright©2001O'Reilly&Associates,Inc.AllRightsReserved.
Symbols|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|
V|W|X|Y|Z
Index:B
baseDN(LDAP):6.4.3.PerformingLDAPSearches
BerkeleyDB
format:9.5.4.1.UsingPerl-onlydatabases
module:8.3.3.1.Checkingagainstalocalblacklist
BerkeleyFastFileSystem:2.2.1.Unix
bigbuffyprogram:9.4.2.CircularBuffering
bindDN(LDAP):6.4.2.TheInitialLDAPConnection
blacklists,checkingspamagainst
Internet-wide:8.3.3.2.CheckingagainstInternet-wideblacklists
local:8.3.3.1.Checkingagainstalocalblacklist
blatprogram:8.1.1.Gettingsendmail(orSimilarMailTransportAgent)
bots:4.4.2.TrackingOperationsinUnix
securityand:4.3.4.UsingtheProc::ProcessTableModule
BSD4.4passwordfiles:3.1.3.BinaryDatabaseFormatinBSD4.4
buildingaccountsystems:3.3.BuildinganAccountSystemtoManageUsers
Symbols|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|
V|W|X|Y|Z
Copyright©2001O'Reilly&Associates,Inc.AllRightsReserved.
Symbols|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|
V|W|X|Y|Z
Index:C
chpasswdcommand(BSD4.4):3.1.3.BinaryDatabaseFormatinBSD4.4
cicommand(RCS):A.TheFive-MinuteRCSTutorial
CIM(CommonInformationModel):4.2.4.UsingWindowManagement
Instrumentation(WMI)
CIMSchema:4.2.4.UsingWindowManagementInstrumentation(WMI)
clogprogram:10.4.1.PerlSavestheDay
closureprogrammingconstruct:8.2.1.1.Controllingthefrequencyofmail
cocommand(RCS):A.TheFive-MinuteRCSTutorial
CollaborativeDataObjectsLibrary:8.1.2.UsingtheOS-SpecificIPC
Framework.
COM(ComponentObjectModel):4.2.4.UsingWindowManagement
Instrumentation(WMI)
6.5.1.ADSIBasics
CommonInformationModel(CIM):4.2.4.UsingWindowManagement
Instrumentation(WMI)
ComponentObjectModel(seeCOM)
ComprehensivePerlArchiveNetwork(seeCPAN)
configurationfiles
DNS
administrativeheader:5.3.1.1.Creatingtheadministrativeheader
generatingmultiple:5.3.1.2.Generatingmultipleconfigurationfiles
reading,securityof:1.6.3.BeCarefulWhenReadingData
containerobjects(COM):6.5.1.ADSIBasics
6.5.3.DealingwithContainer/CollectionObjects
identifying:6.5.4.IdentifyingaContainerObject
CPAN(ComprehensivePerlArchiveNetwork):1.5.LocatingandInstalling
Modules
modules,installingonUnix:1.5.1.InstallingModulesonUnix
CPANSearch:1.5.LocatingandInstallingModules
Crackprogram:10.5.PreventingSuspiciousActivities
Symbols|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|
V|W|X|Y|Z
Copyright©2001O'Reilly&Associates,Inc.AllRightsReserved.
Symbols|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|
V|W|X|Y|Z
Index:D
DataSourceName(DSN):7.3.UsingtheODBCFramework
datastructures,transforming:3.3.1.4.WritingXMLusingXML::Simple
databasehandle,DBI:7.3.UsingtheODBCFramework
DatabaseInterface(seeDBI)
databases
analyzinglogfileswith:9.5.4.UsingDatabases
generatingDNSconfigurationfilesfrom:5.3.1.GeneratingDNS
ConfigurationFiles
generatinghostfilesfrom:5.1.1.GeneratingHostFiles
errorcheckingwhile:5.1.2.ErrorCheckingtheHostFileGeneration
Process
improvingoutputwhile:5.1.3.ImprovingtheHostFileOutput
MySQL:D.TheFifteen-MinuteSQLTutorial
relational:D.5.RelatingTablestoEachOther
SAM:3.2.1.NT/2000UserIdentityStorageandAccess
SQL
creating/deleting:D.1.Creating/DeletingDatabasesandTables
documentingfromPerl:7.4.ServerDocumentation
interactingwithfromPerl:7.1.InteractingwithanSQLServerfrom
Perl
managingloginsfromPerl:7.5.DatabaseLogins
manipulatingdatain:D.3.3.SimpleManipulationofDataReturnedby
Queries
monitoringfromPerl:7.6.MonitoringServerHealth
Perl-cliented:9.5.4.2.UsingPerl-clientedSQLdatabases
queryinginformation:D.3.QueryingInformation
storedprocedures:D.6.3.StoredProcedures
usingDBI:7.2.UsingtheDBIFramework
usingODBC:7.3.UsingtheODBCFramework
trackingnetworkhostdatawith:5.1.1.GeneratingHostFiles
useinaccountsystems:3.3.1.TheBackendDatabase
DBAs(databaseadministrators):7.SQLDatabaseAdministration
DBDmodules:7.1.InteractingwithanSQLServerfromPerl
DBD\:\:ODBCmodule:7.1.InteractingwithanSQLServerfromPerl
7.1.InteractingwithanSQLServerfromPerl
DBD\:\:Sybasemodule:7.1.InteractingwithanSQLServerfromPerl
DB_Filemodule:9.5.4.1.UsingPerl-onlydatabases
DBI(DatabaseInterface)
modulefordocumenting
MySQLserver:7.4.1.MySQLServerviaDBI
Sybaseserver:7.4.2.SybaseServerviaDBI
architectureof:7.1.InteractingwithanSQLServerfromPerl
databasehandle:7.3.UsingtheODBCFramework
placeholders:7.2.UsingtheDBIFramework
statementhandle:7.2.UsingtheDBIFramework
usingfromPerl:7.2.UsingtheDBIFramework
denial-of-serviceattack:10.4.1.PerlSavestheDay
Dial-UpUserList:8.3.3.2.CheckingagainstInternet-wideblacklists
Digest\:\:MD5module:10.1.1.LocalFilesystemChanges
10.1.2.NetworkServiceChanges
directories:6.1.What'saDirectory?
auditing:4.4.1.TrackingOperationsonWindowsNT/2000
entriesin
adding/deleting:6.4.6.AddingEntrieswithStandardLDAP
Operations
modifying:6.4.8.ModifyingEntryNames
hidden,searchingfor:10.2.1.LocalSignsofPeril
searchesof
ADSI:6.5.6.Searching
LDAP:6.4.3.PerformingLDAPSearches
DirectoryInformationTree(DIT):B.1.LDAPDataOrganization
directoryservices:6.DirectoryServices
Finger:6.2.Finger:ASimpleDirectoryService
LDAP:6.4.LDAP:ASophisticatedDirectoryService
WHOIS:6.3.TheWHOISDirectoryService
Net\:\:Whois,usingwith:6.3.TheWHOISDirectoryService
X.500:6.4.LDAP:ASophisticatedDirectoryService
directorytree:B.1.LDAPDataOrganization
disks,full
alleviating:2.4.WalkingtheFilesystemUsingtheFile::FindModule
ofloggingoutput:9.4.DiskSpaceProblems
DistinguishedName(DN):B.1.LDAPDataOrganization
DistributedManagementTaskForce(DMTF):4.2.4.UsingWindow
ManagementInstrumentation(WMI)
DIT(DirectoryInformationTree):B.1.LDAPDataOrganization
DMTF(DistributedManagementTaskForce):4.2.4.UsingWindow
ManagementInstrumentation(WMI)
DN(DistinguishedName):B.1.LDAPDataOrganization
root:6.4.2.TheInitialLDAPConnection
DNS(DomainNameService):5.3.DomainNameService(DNS)
configurationfiles
administrativeheader:5.3.1.1.Creatingtheadministrativeheader
generatingmultiple:5.3.1.2.Generatingmultipleconfigurationfiles
packets:5.3.2.2.Workingwithrawnetworksockets
queryingfromPerl
usingNet\:\:DNS:5.3.2.3.UsingNet::DNS
usingnslookup:5.3.2.1.Usingnslookup
usingrawsockets:5.3.2.2.Workingwithrawnetworksockets
DocumentTypeDefinition(DTD):C.2.XMLIsPicky
documentingdatabases
withDBImodule
MySQLserver:7.4.1.MySQLServerviaDBI
Sybaseserver:7.4.2.SybaseServerviaDBI
withWin32\:\:ODBCmodule,MS-SQLserver:7.4.3.MS-SQLServervia
ODBC
DomainNameService(seeDNS)
driver,Linux:2.1.PerltotheRescue
DSN(DataSourceName):7.3.UsingtheODBCFramework
DTD(DocumentTypeDefinition):C.2.XMLIsPicky
dynamicallylinkedlibraries(DLLs),usedbyprocesses:4.2.2.Usingthe
Win32::IProcModule
Symbols|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|
V|W|X|Y|Z
Copyright©2001O'Reilly&Associates,Inc.AllRightsReserved.
Symbols|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|
V|W|X|Y|Z
Index:E
edquotacommand(Unix):2.5.1.EditingQuotaswithedquotaTrickery
eggdropbot:4.3.4.UsingtheProc::ProcessTableModule
ElDumpprogram:9.5.1.StreamRead-Count
electronicmail(seeemail)
email
assupportmedium:8.3.4.SupportMailAugmentation
dissectingmailboxes/messages:8.3.ReceivingMail
logfileparsing:9.5.3.BlackBoxes
relaying:8.3.3.TrackingDownSpam
sendingfromPerl:8.1.SendingMail
limitingfrequncyandamountof:8.2.1.1.Controllingthefrequencyof
mail
MacOS:8.1.2.UsingtheOS-SpecificIPCFramework.
mistakesin:8.2.CommonMistakesinSendingEmail
WindowsNT/2000:8.1.1.Gettingsendmail(orSimilarMailTransport
Agent)
8.1.2.UsingtheOS-SpecificIPCFramework.
spam(seespam)
subjectlineof,writinguseful:8.2.2.SubjectLineWaste
supportmail,augmenting:8.3.4.SupportMailAugmentation
toolforsystemadministration:8.ElectronicMail
/etc/hosts:5.1.HostFiles
5.1.HostFiles
5.2.NIS,NIS+,andWINS
/etc/passwd:5.2.NIS,NIS+,andWINS
securityand:10.1.1.LocalFilesystemChanges
Eudoraprogram:8.1.2.UsingtheOS-SpecificIPCFramework.
eventhandlers:3.3.1.2.ReadingXMLusingXML::Parser
EventLogService:9.2.3.UsingtheOS'sLoggingAPI
EventViewerprogram:9.2.3.UsingtheOS'sLoggingAPI
ExtensibleMarkupLanguage(seeXML)
Symbols|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|
V|W|X|Y|Z
Copyright©2001O'Reilly&Associates,Inc.AllRightsReserved.
Symbols|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|
V|W|X|Y|Z
Index:F
FATfilesystems:2.2.2.MicrosoftWindowsNT/2000
fileoperations:4.UserActivity
tracking
Unix:4.4.2.TrackingOperationsinUnix
WindowsNT/2000:4.4.1.TrackingOperationsonWindowsNT/2000
fileshares,managingwithADSI:6.5.10.WorkingwithFileSharesviaADSI
File\:\:Findmodule:2.4.WalkingtheFilesystemUsingtheFile::FindModule
onMacOS:2.4.WalkingtheFilesystemUsingtheFile::FindModule
onUnix:2.4.WalkingtheFilesystemUsingtheFile::FindModule
2.4.WalkingtheFilesystemUsingtheFile::FindModule
onWindowsNT:2.4.WalkingtheFilesystemUsingtheFile::FindModule
findinghiddendirectorieswith:10.2.1.LocalSignsofPeril
whennottouse:2.4.WalkingtheFilesystemUsingtheFile::FindModule
filenames,long,finding:2.4.WalkingtheFilesystemUsingtheFile::Find
Module
files
auditingonWindowsNT/2000:4.4.1.TrackingOperationsonWindows
NT/2000
changesto,detecting:10.1.1.LocalFilesystemChanges
finding
core:2.3.WalkingorTraversingtheFilesystem
damaged:2.1.PerltotheRescue
2.3.WalkingorTraversingtheFilesystem
extraneous:2.4.WalkingtheFilesystemUsingtheFile::FindModule
WindowsNT/2000hidden:2.4.WalkingtheFilesystemUsingthe
File::FindModule
locking:3.3.4.AccountSystemWrap-Up
log(seelogfiles)
open,tracking:4.4.1.TrackingOperationsonWindowsNT/2000
writingto,securityof:1.6.4.BeCarefulWhenWritingData
9.4.2.2.Securityinlogprocessingprograms
File\:\:Specmodule:2.2.5.DealingwithFilesystemDifferencesfromPerl
File\:\:Statmodule:10.1.1.LocalFilesystemChanges
Filesys\:\:Dfmodule:2.6.QueryingFilesystemUsage
Filesys\:\:DiskFreemodule:2.6.QueryingFilesystemUsage
Filesys\:\:DiskSpacemodule:2.6.QueryingFilesystemUsage
filesystems
BerkeleyFastFileSystem:2.2.1.Unix
differencesbetween:2.2.FilesystemDifferences
FAT:2.2.2.MicrosoftWindowsNT/2000
MacOS:2.2.3.MacOS
NTFS:2.2.2.MicrosoftWindowsNT/2000
queryingusage:2.6.QueryingFilesystemUsage
traversing/walking:2.3.WalkingorTraversingtheFilesystem
MacOS:2.4.WalkingtheFilesystemUsingtheFile::FindModule
Unix:2.3.WalkingorTraversingtheFilesystem
WindowsNT/2000:2.3.WalkingorTraversingtheFilesystem
Unix:2.2.1.Unix
VFAT:2.2.2.MicrosoftWindowsNT/2000
WindowsNT/2000:2.2.2.MicrosoftWindowsNT/2000
findingdamagedfileson:2.3.WalkingorTraversingtheFilesystem
find2perlcommand:2.4.WalkingtheFilesystemUsingtheFile::FindModule
Finger:6.2.Finger:ASimpleDirectoryService
fpingprogram:10.4.1.PerlSavestheDay
FreeTDSlibraries:7.1.InteractingwithanSQLServerfromPerl
FreezeThawmodule:9.5.4.1.UsingPerl-onlydatabases
10.1.2.NetworkServiceChanges
FTPtransfers,correlating:9.5.2.Read-Remember-Process
Symbols|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|
V|W|X|Y|Z
Copyright©2001O'Reilly&Associates,Inc.AllRightsReserved.