Tải bản đầy đủ (.pdf) (844 trang)

Apress automating UNIX and linux administration sep 2003 ISBN 1590592123

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (2.76 MB, 844 trang )

AutomatingUNIXandLinux
Administration
byKirkBauer
Apress©2003

ISBN:1590592123

Thisbookfocusesonautomatingthetedious
dailytasksofsystemadministration.It
providesreal-worldexamplesandexploresthe
toolsusefulformanaging2or5,000systems.
TableofContents
AutomatingUNIXandLinuxAdministration
Preface
Chapter1 - IntroducingtheBasicsofAutomation
UsingSSHtoSecurelyAutomateSystem
Chapter2 Administration
Chapter3 - CreatingLoginScriptsandShellScripts
Pre-Installation—NetworkPreparation
Chapter4 andManagement
Chapter5 - AutomatingandCustomizingInstallation
Chapter6 - AutomaticSystemConfiguration
Chapter7 - SharingDataBetweenSystems
Chapter8 - PackagesandPatches
Chapter9 - SystemMaintenanceandChanges
Chapter10 - SystemMonitoring
Chapter11 - ImprovingSystemSecurity
Chapter12 - BackingUpandRestoringData
Chapter13 - UserInterfaces
AppendixA - IntroductiontoBasicTools



AppendixB - CustomizingandAutomatingRedHat
LinuxInstallation
BuildingRedHatPackageManager(RPM)
AppendixC Packages
Index
ListofFigures
ListofTables
ListofSidebars


BackCover
Wouldn’tyouliketoautomatethetediousdailytasks
ofsystemadministration?AutomatingUNIXandLinux
Administrationwillshowyouhow,byexploringexisting
toolsandofferingreal-worldexamples.Partsofthe
bookareLinux-specific,butmostofitappliestoa
UNIXsystem,includingmultiplevariantsofUNIX.
AuthorKirkBauerbrieflyoverviewstoolsand
technologies—andassumespreliminaryknowledge
abouteditingaconfigurationfileormountingafile
system.
Thetechniques,methods,andtoolsinthisbookwill
helpyoumanageasinglesystem—butwillprove
especiallypowerfulacrossmultiplesystems.Nomatter
ifthesystemsaredesktops,servers,orBeowulf
clusters—allofthemwillbenefitfromthisautomation.
Andmanagingfivetofivethousandsystemswill
becomeasimplertask!
AbouttheAuthor

KirkBauerhasbeeninvolvedincomputer
programmingsince1985.Hehasbeenusingand
administeringUNIXsystemssince1994.Althoughhis
personalfavoriteUNIXvariantisLinux,hehas
administeredanddevelopedoneverythingfrom
FreeBSDtoSolaris,AIX,andIRIX.Heistheauthorof
variousopen-sourcesystemadministrationprograms
suchasAutoRPMandLogwatch.
Bauerhasbeeninvolvedwithsoftwaredevelopment
andsystem/networkadministrationsincehisfirstyear


atGeorgiaTech.HehasdoneworkfortheGeorgia
TechResidentialNetwork,theGeorgiaTechResearch
Institute,andtheFermiNationalAccelerator
Laboratory.Bauerwasoneofthefoundersandthe
CTOofTogetherWebin2000,whichwaspurchasedin
2003byProficientSystems.Heiscurrentlyasoftware
architectwithProficientSystems,andcontinuesto
supportanddevelopthecollaborativebrowsing
softwareandLinux-basednetworkappliancecreated
byTogetherWeb,includingC++serversoftwarethat
provideshighscalability,highefficiency,andhigh
reliability.
KirkgraduatedfromGeorgiaTechin2001witha
bachelor’sdegreeincomputerengineering.Shortly
thereafter,hebeganworkonhisfirstbook,
AutomatingUNIXandLinuxAdministration,whichwas
publishedbyApressinSeptember2003.



AutomatingUNIXandLinuxAdministration
KirkBauer
Apress™
Copyright©2003KirkBauer
Allrightsreserved.Nopartofthisworkmaybereproducedortransmitted
inanyformorbyanymeans,electronicormechanical,including
photocopying,recording,orbyanyinformationstorageorretrieval
system,withoutthepriorwrittenpermissionofthecopyrightownerand
thepublisher.
(pbk):
1-59059-212-3
10987654321
Trademarkednamesmayappearinthisbook.Ratherthanusea
trademarksymbolwitheveryoccurrenceofatrademarkedname,weuse
thenamesonlyinaneditorialfashionandtothebenefitofthetrademark
owner,withnointentionofinfringementofthetrademark.
TechnicalReviewers:NateCampi,ErikMelander,AlfWachsmann
EditorialBoard:DanAppleman,CraigBerry,GaryCornell,TonyDavis,
StevenRycroft,JulianSkinner,MartinStreicher,JimSumser,Karen
Watterson,GavinWray,JohnZukowski
AssistantPublisher:GraceWong
CopyEditor:RebeccaRider
ProductionManager:KariBrooks
Proofreader:LauraCheu
Compositor:SusanGlinertStevens
Indexer:KevinBroccoli
CoverDesigner:KurtKrames
ManufacturingManager:TomDebolski
DistributedtothebooktradeintheUnitedStatesbySpringer-VerlagNew



York,Inc.,175FifthAvenue,NewYork,NY,10010andoutsidetheUnited
StatesbySpringer-VerlagGmbH&Co.KG,Tiergartenstr.17,69112
Heidelberg,Germany.
IntheUnitedStates:phone1-800-SPRINGER,email,orvisit.OutsidetheUnitedStates:
fax+496221345229,email,orvisit
.
Forinformationontranslations,pleasecontactApressdirectlyat2560
NinthStreet,Suite219,Berkeley,CA94710.Phone510-549-5930,fax
510-549-5939,email,orvisit.
Theinformationinthisbookisdistributedonan"asis"basis,without
warranty.Althougheveryprecautionhasbeentakeninthepreparationof
thiswork,neithertheauthor(s)norApressshallhaveanyliabilitytoany
personorentitywithrespecttoanylossordamagecausedorallegedto
becauseddirectlyorindirectlybytheinformationcontainedinthiswork.
Thesourcecodeforthisbookisavailabletoreadersat
intheDownloadssection.
Tomyparents,especiallymyfather,whostartedandsupportedmy
interestincomputers,andmylovingwifeAmber,whohassupported
methroughoutthisprocess.
AbouttheAuthor
KirkBauerhasbeenusingcomputersandprogrammingsince1985.He
hasbeenusingandadministeringUNIXsystemssince1994.Although
hispersonalfavoriteUNIXvariantisLinux,hehasadministered
everythingfromFreeBSDtoSolaris,AIX,andIRIX.
Kirkhasbeeninvolvedwithsoftwaredevelopmentandsystem/network
administrationsincehisfirstyearatGeorgiaTech.Hehasdoneworkfor
theGeorgiaTechResidentialNetwork,theGeorgiaTechResearch
Institute,andtheFermiNationalAcceleratorLaboratory.Kirkwasoneof

thefoundersandtheCTOofTogetherWebin2000,whichwas
purchasedin2003byProficientSystems.Kirkiscurrentlyasoftware


architectwithProficientSystemsandcontinuestosupportanddevelop
thecollaborativebrowsingsoftwareandLinux-basednetworkappliance
createdbyTogetherWeb.
Kirk'slatestdevelopmentisafullyautomatedinstallation,configuration,
management,andmonitoringsystemthatisusedtodeployProficient's
softwareonRLXServerBlades.Savingtimethroughautomationhas
alwaysbeenhispassion,asevidencedbyhiscollectionofopen-source
software—themostpopularbeingAutoRPMandLogwatch.
ShortlyaftergraduatingfromGeorgiaTechin2002withabachelor'sof
scienceinComputerEngineering,KirkmarriedAmber,theloveofhislife.
TheycurrentlyliveinPeoria,AZwiththeirtwodogsandfourcats.When
notusingacomputer,Kirkcanbefoundinvolvedinoneofhismany
hobbies.Kirkenjoysreading,playingstrategygames,takingpictures,
andwatchingmovies.Helikestosnowski,waterski,andscubadive
whenhegetstheopportunity.Skydivingishisfavoritesport—Kirkhas
madeover1,400jumpstodate.
AbouttheTechnicalReviewers
NateCampiisaUNIXandnetworkadministratorinSiliconValley.Heis
currentlyemployedata(Linux-based)networkappliancevendor,running
allaspectsoftheirinternalIT,helpingguidedevelopmentofproducts,
anddesigningDNSarchitecturesforcustomers.
Pastjobsincludepostmaster,hostmaster,andwebmasterdutiesatTerra
Lycos,UNIXandnetworkadministratoratseveralSiliconValleyweb
hostingcompanies,andatourasahospitalcorpsmanintheUSNavy.
WhileintheNavy,Natedevelopedaloveofteachingasainstructorfor
basicandadvancedlifesupport,andalsopediatricadvancedlifesupport

fortheAmericanHeartAssociation.
Heismarried,hasasonandadaughter,livesintheSanFranciscoEast
Bay,anddreamsofonedayowningahomeinthearea.
ErikMelander,ManagingArchitectofCentralSystemsatWyndham
International,hasadecadeofexperiencewithUNIXsystems,including
timeworkingwiththeUniversityofMinnesotaandIBMGlobalServices.


Currently,heisevolvingWyndham'sITinfrastructuretorealizeashared
visionofautonomiccomputing.
AlfWachsmannholdsadoctorateofnaturalscienceinComputer
SciencefromtheUniversityofPaderborninGermany.Hewrotehis
thesisaboutparallelanddistributedcomputing.
HethenworkedatDESY,Germany'snationalhigh-energyphysicslab,
wherehelearnedsystemsoftwareprogrammingandsystem
administrationinaveryheterogeneousUNIXenvironment.Hisspecialty
becameautomation.
WachsmannthenmovedfromGermanytotheSanFranciscoBayarea,
wherehenowworksattheStanfordLinearAcceleratorCenter,asite
withfewerUNIXversionsbutwithalotmorecomputers.Hismainfocus
isagainautomatingsystemadministrationandsysteminfrastructure
tasks.
OtherprofessionalinterestsincludetheOpenAFSfilesystemand
Kerberos5authentication.
Acknowledgments
IhaveusedcomputerssinceIwasveryyoungandhavealwaysloved
them,thanksinlargeparttothesupportofmyparentsthroughoutmy
childhood.Theyhavealwayshelpedmelearnandhavesupportedmein
whateverIwantedtodo.Ihavetoparticularlythankmyfatherwho,much
tomyMom'schagrin,camehomeonedaywithmyveryfirstcomputer—

aCommodoreVic20.Mylifewasneverthesameafterthat.
Ialsothankmylovelywife,Amber,whohassharedmewiththisbookfor
many,manymonths.Shehasbeensupportiveandunderstanding,even
thoughIstartedwritingthebookjustafterourhoneymoonwasover.
Inaddition,myfriendandcolleagueMosheJacobsonhasbeenvery
helpfulinthisprocess.Hequicklyansweredmymanyquestionsand
evendidsomeofthetechnicalreview.Hehelpedmakewritingthisbook
thelearningexperiencethatitwas.


Finally,ImustthankeverybodyatApressforhelpingmethroughmyfirst
book—especiallymyeditor,JimSumser,whohasstuckbymethrough
thislongandarduousprocess.


Preface
Admitit.Youarereadingthisbookbecauseyouarelazy.Lazysystem
administratorsarewonderfulpeople—whoelseiswillingtospendso
muchtimenowinordertodonothinglater?Wealldreamofwakingupin
themorning,grabbingthelaptopfromthebedsidetable,checkingour
email,andthenheadingofftothelakefortheday.
Usingthetechniquesinthisbook,youcangetclosertotheidealworldof
fullyautomatedsystemadministration.Althoughunexpectedthings
alwaysgowrong,wecanatleastdelegateallofthemundaneand
repetitivetaskstothecomputer(whosepurpose,ofcourse,wastomake
ourliveseasier).Iwillleaveituptoyoutoconvinceyourbossthatyou
onlyneedtocomeintoworkonedayperweek.


BenefitsofAutomation

Inmostcases,themotivationbehindautomationissavingtime.Weare
busypeopleandourtimeisvaluable.Wewouldratherwriteascriptto
addauserthanaddonemanuallyafewtimesaday.Wecanthentake
thattimewesaveandspenditdoingthingsthataren'taseasyto
automate(orthingsthataremuchmoreentertaining).Thereareother
benefitsofautomation,however,thatarenotquiteasapparent.
Inmanycases,automationallowsotherstodothingsthattheydon'thave
enoughdirectknowledgetodothemselves.Theseotherpeoplerange
frominexperiencedsystemadministratorsworkingunderyoutosupport
staffmanningthecorporatehelpdesk.Yourautomationmakes
everybody'slivesmucheasier.Theydon'thavetobotheryousomuch,
andyoudon'thavetoanswerthesamequestionseveryday.
Equallyimportantistheunintentionaldocumentationthatcanresultfrom
automation.Forexample,toaddanewaccount,youhavetoaddittothe
passwd,shadow,andgroupfiles,aswellascreateahomedirectory
onthefileserverandsetuptheautomounttables.Althoughyounormally
thoroughlydocumentandfollowstep-by-stepproceduresformostofyour
administrationtasks,yousomehowmanagetoneglectthisparticular
task.
Thisiswhereautomationisveryhelpful.Ifyouwriteascripttodoallof
thetasksrequiredtocreateauser,youhaveeffectivelywrittenastep-bystepguideexplaininghowtocreateanewaccount.Ifyouputsomegood
commentsinthescript,youhavedocumentedtheprocessaswell.The
scriptcomesinhandywhenyouhaven'taddedanewaccountforthree
months.Evenifthescriptisdatedandfailstooperatecorrectly,youstill
knowwhatwassupposedtohappenandthatitwassupposedtowork.
Insteadofhavingtore-createtheprocessfromscratch,youcanjust
tweakthescriptsothatitwillworkthistimeandthenext.


UsesforAutomationTechniques

Automationcanbebeneficialevenwhenitislimitedtoonesystem.
Regardlessofhowsimplethesystemisorhowlittleitdoes,menialtasks
stillneedtobedone,logsneedtobemonitored,andsoon.Ofcourse,
thebenefitsofautomationreallystarttooutweighthecostswhenitis
deployedacrossseveralsystems.
Managinghundredsoreventhousandsofmachinescanbefun.Itcan
alsobeanightmareifthingsarenotdoneright.Toavoidthisandreduce
yourfutureworkload,makesuretodothingscorrectlyfromthestart.
However,therearealsomanythingsyoucandotomakelifeeasierwhen
youaremanagingexistingsetsofmachines.Soevenifyoucan'tstart
fromscratch,youmaystillfindthisbookveryhelpful.Forexample,aswe
willdiscusslater,youcanusemethodstoautomaticallystandardize
machinesinyourexistingnetwork.
Ifyouaremanagingmorethanonemachine,youprobablythinkthatit
wouldbeniceifallofthemachineshadthesamehardware,operating
system,andsoftware.Sometimesthisispossible(ifyouareusing
Beowulfclusters,forinstance);usuallyitisnot(especiallyinasoftware
engineeringcompanywith1,000programmers).Thisbookdealswith
bothuniformandmixedUNIXenvironments.AlthoughtheexamplesI
useonlydirectlyapplytoLinuxandUNIXenvironments,youcanapply
theseideastoanysituation.


WhoWillBenefit?
Ihavewrittenthisbookfortheexperiencedsystemadministrator.This
doesn'tmeanthatyouhavetobeanexpert,itjustmeansthatyouneed
tohavealittleexperiencebeforeyouwillfindthisbookvaluable.For
instance,ifyoucan'trememberhowtomountafilesystemwithout
lookingitupinareferencemanual,thenthisbookmaybetooadvanced
foryou.

Inadditiontoassumingthatyoucanperformbasicsystemadministration
tasks,IassumethatyouarefamiliarwithbothPerland/orbashscripting.
Inaddition,Iexpectyoutounderstandbasicregularexpressionsyntax.
IfyouareastudentandarerunningaLinuxserver,thenthisbookcould
beforyou.IfyouhaveafewUNIXboxesatwork,thenyouwillprobably
findthisbookuseful.IfyouadministerafewUNIXworkstations,asetof
UNIXservers,awebfarm,oraBeowulfcluster,thenthisbookcouldbea
lifesaver.


TechniquesCovered
Youcantakeoneofthreeapproacheswhenyougotosolvethe
automationproblemsIpresentinthisbook:
Open-sourcesoftware:Open-sourcesolutionsexistformanyofthe
problemsIpresentinthisbook,butIdonotattempttocoverevery
opensourcesolutiontoeveryproblem.Instead,Icoverthemost
popularandmaturesoftwareineachcategory.SomeprogramsI
coverincludeGNUcfengine,Logwatch,Swatch,AutoRPM,and
NetSaint(whichiscurrentlybeingdevelopedasNagios).Thisbook
isnotacompleteinstructionmanualforanyofthissoftware,butit
doesprovideenoughinformationforyoutoconsiderandbeginto
usetheseprograms.
Customscriptsandsoftware:Anotherfocusofthisbookinvolves
customsolutions.WhyamIadvocatingcustomsolutionswhen
open-sourcesolutionsalreadyexist?I'mnot.Idefinitelyrecommend
thatyouuseexistingsolutionswhenpossible.However,thereare
manycasesinwhichexistingsolutionsaretoocomplicated,arenot
powerfulenough,oraretoorestrictiveforyourparticularneeds.In
addition,therearealsoplentyofareaswithinautomationwhere
existingsolutionsarehardtocomeby.Thisisusuallybecausethe

situationissignificantlydifferentineachcaseorthesolutionistoo
simpletoreleaseasaproduct.
Commercialsoftware:Idonotcovercommercialsoftwareinthis
book—notbecausethereisanythingwrongwiththesoftware,itis
justtoocostlyformanysituations(especiallywhenyouconsiderthe
consultingcoststypicallyassociatedwiththistypeofsoftware).In
addition,notenoughinformationisavailableonthecommercial
solutionsformetofullydiscussthemwithinthisbook.However,for
somesituationscommercialsoftwaremaybethebestsolutionandI
suggestthatyouconsideritifitfitsyourneeds.


ChapterSummary
Thebookbeginswithintroductorychaptersthatyoushouldbevery
familiarwithbeforeyoumoveontothemeatofthetext.Itthenproceeds
withonechapteroneachcoreareaofautomation.Eachchapterfully
discussestheareainquestion,describesbothexistingandcustom
solutionstoeachproblem,andprovidesnumerousexamples.
Chapter1:IntroducingtheBasicsofAutomationcoversthe
methodologybehindsystemadministration.automation.
Chapter2:UsingSSHtoSecurelyAutomateSystem
Administration
coversthebasicsofusingSecureShell(SSH),discussesSSH
securityconcerns,describeshowtosetuppasswordlessSSH,and
delvesintovariousotherrelatedtopics.
Chapter3:CreatingLoginScriptsandShellScriptsdiscusses
somemoreadvancedfeaturesofbashandhowyoucanusethemto
customizeyourprompt,createcommandaliases,enhancetab
completion,andotherwiseenhanceyourshellexperience.This
chapteralsoprovidesscriptsthatallowcommandstorunacross

multiplesystems.
Chapter4:Pre-Installation:NetworkPreparationand
Management
discussesthetasksyouneedtocompletetoaddanewsystemto
yournetworkandprovidesacustom,modularshellscriptyoucan
usetoautomatethesetasks.
Chapter5:AutomatingandCustomizingInstallationdiscusses
theoptionsavailabletoyouwhenyouwanttoautomaticallyperform
operatingsysteminstallations.Thischapteralsodiscussesyour
optionsforcustomizingyouroperatingsystemsandprovidesscripts
thatallowanewsystem(evenwithoutacustomoperatingsystem)to
quicklyandeasilyjoinyourautomationsystem.


Chapter6:AutomaticSystemConfigurationcoverstheautomatic
configurationallofthesystemsonyournetwork,regardlessofthe
operatingsystemstheyrunorthetaskstheyperform.Thischapter
providesbothacustomsolutionandacomprehensivediscussionof
<application>GNUcfengine</application>.
Chapter7:SharingDataBetweenSystemsdiscussesmany
methodsyoucanusetosharedataamongyourvarioussystems
andtalksaboutnetworkfilesystemssuchastheNetworkFile
System(NFS),NetworkInformationServices(NIS/NIS+),GNU
cfengine,rsync,ConcurrentVersioningSystem(CVS),andthe
HypertextTransferProtocol(HTTP)andtheFileTransferProtocol
(FTP)protocols.
Chapter8:PackagesandPatchesdiscussestheissuesinvolvedin
updatingmanysystems.ThischapteralsotalksaboutbothSolaris
andcustompatches,theRedHatPackageManager(RPM)and
Debianpackageformats,andacustompackagesolution.In

addition,itcoversautomaticpackageinstallationwithAutoRPMand
introducestheOpenPKGsystem,whichprovidespackagesthatcan
beinstalledonmanydifferentoperatingsystems.
Chapter9:SystemMaintenanceandChangescoversthevarious
maintenancetasksinherentinmostmodernoperatingsystems.This
includestimesynchronization,accountmanagement,logfile
rotation,andgeneralsystemcleanup.
Chapter10:SystemMonitoringintroducestechniquesfor
monitoringyoursystems.ThischapterpresentsLogwatchand
swatchforlogmonitoringandNetSaintfornetworkmonitoring.
Chapter11:ImprovingSystemSecuritydiscussestoolsthatcan
enhanceyoursystem'ssecuritywithminimalmaintenanceonyour
part.ThischapteralsoshowsyouhowtouseandconfigureTripwire,
howtocreateautomaticfirewallconfigurations,andhowtouseGNU
cfenginetoincreaseyoursystemandnetworksecurity.
Chapter12:BackingUpandRestoringDatapresentssimpleand
inexpensivesolutionsforautomaticallybackingupyoursystems'


data.
Chapter13:UserInterfacesshowsyouhowtocreateboth
console-andweb-baseduserinterfacesforyourautomationsystem
usingbash,Perl,andMason.
AppendixA:IntroductiontoBasicToolsprovidesabasic
introductiontothetoolsusedthroughoutthebookandprovidesa
goodstartingpointforunderstandingandutilizingtheexamples
presentedinthistext.Thisappendixcoversthefollowingtools:bash,
Perl,grep,sed,andawk.
AppendixB:CustomizingandAutomatingRedHatLinux
Installation

showsyouhowtoautomatetheinstallationofRedHatLinux.Also
thisappendixshowsyouhowtocreateyourowncustomLinux
distributionderivedfromRedHatLinux.
AppendixC:BuildingRedHatPackageManager(RPM)
Packageshousescomprehensiveinstructionsonhowtobuildyour
ownRPMs.


AdditionalResources
Theprocessofautomatingsystemadministrationcoversawiderangeof
topics.Throughoutthebook,Iwillsuggestadditionalreadingmaterial.
Also,thereareseveraladditionalbooksthatyouwillmostlikelyfind
helpfulandIwouldliketomentionthemhere:
UNIXSystemAdministrationHandbook(3rdEdition),byEvi
Nemeth,GarthSnyder,ScottSeebass,TrentR.Hein(Prentice
Hall,2000).Thisbookcoversalmostanythingyoueverwantedto
knowaboutUNIXsystemadministration.
PrinciplesofNetworkandSystemAdministration,byMark
Burgess(JohnWiley&Sons,2000).Thisbookdiscussesthe
theoryandprinciplesbehindgoodnetworkandsystem
administration.
UnixStorageManagement,byRayA.KampaandLydiaV.Bell
(Apress,2002).Thisbookcoverseverythingyoueverwantedto
knowaboutstoringdataonUNIXsystems.
LearningthebashShell,byCameronNewhamandBill
Rosenblatt(O'ReillyandAssociates,1998).Thisbookcoversthe
bashcommandshellaswellasbashshellscripting.
LearningPerl,byRandalL.SchwartzandTomPhoenix(O'Reilly
andAssociates,2001).Thisisthefirstplacetostartifyouwantto
learnPerl,averypowerfulscriptinglanguagethatisused

extensivelythroughoutthisbook.
ProgrammingPerl,byLarryWalletal.(O'ReillyandAssociates,
2000).ThismoreadvancedguidetoPerlprovidesextensive
referencematerial.
PerlforSystemAdministration,byDavidN.Blank-Edelman
(O'ReillyandAssociates,2000).YoualreadyknowweusePerl
extensivelyinthisbook.Bylookingatthetitle,youalsoprobably
knowthatthisbookisaboutautomatingsystemadministration.
Anyquestions?


PracticalUNIX&InternetSecurity,bySimsonGarfinkel,Alan
Schwartz,andGeneSpafford(O'ReillyandAssociates,2003).
Thisbookdiscussessecurity,whichshouldalwaysbeonyour
mind,especiallywhenyouautomatingsystemadministration.


ConventionsUsedinThisBook
Ihaveusedseveralspecialfontandformattingconventionsinthisbook.
Thissectionreviewstheseconventionsandhowtheyareapplied.
Herearesomeofthemostcommonformattingconventionsyouwill
comeacross:
Note Notescallattentiontoimportantissuesorinterestingfacts
aboutthegivensubject.
Tip Tipsprovideadditionalinformationaboutthesubjectthatyou
mayfinduseful.
Caution Cautionsservetoalertyouaboutpotentiallydangerousside
effectsyouractionsorthepresentedscriptsmaycause.
Warning Warningsprovideimportantinformationthatyoumustbe
awareofbeforeproceeding,suchaspotentiallyserious

sideeffects.
Sidebars
Sidebarsareusedtoprovidelargeramountsofrelatedinformation
thatyoumayormaynotbeinterestedinreading.

Thisbookcontainsalargenumberofprogramlistings.Sometimesthey
areshownasablockofcode:
#!/bin/bash
echo"hello,howareyou?"
Othertimestheymaybebrokenintosections.Imayfirstdefinea
function:
say_hello(){
echo"Hello,howareyou?"


}
andthenprovidethecodethatcallsthefunction:
case$0in
hello)
say_hello
;;
esac
Totrytheseexamples,youcandownloadthecodesamplesfromthe
DownloadssectionoftheApresswebsite().
Alternatively,youcancreateyourownscriptfilebycombiningthe
separatepartsofthescriptintoonefile,withtheproperinterpreter
declarationatthetop(suchas#!/bin/bash).
Finally,somecodelistingswillhavetheirlinesnumberedandsomeofthe
numberedlineswillbebold.Theselineswillbediscussedinmoredetail
afterthecode.Hereisanexample:

1#!/bin/bash
2
3echo"Hello,howareyou?"
Line1:Runthisusingbashastheinterpreter.
Line3:Outputthestringtostdoutusingtheechocommand.
Throughoutthebook,youwilloftenseeexamplesofcommandsbeing
runasfollows:
%./hello
echo"Hello,howareyou?"
Notethataconstant-widthfontisused,justlikeonaterminal.Anything
thatyoushouldtypeispresentedinbold.
Herearesomeofthemostcommonfontconventionsyouwillcome


across:
Monospaced:Monospacedfontisusedforavarietyofpurposesin
thisbook.Iuseittoidentifyliteralstrings,suchasHello,how
areyou?.IalsouseitforURLs(suchas),
commands(likegrep),filenames(/etc/passwd),andwithin
programlistings.
Bold:Boldisusedtoindicatesomethingthereaderorusershould
type,usuallyatacommandprompt.
Italics:Italicsisusedtoemphasissomethingortoindicatethata
termisbeingdefined.


We'dLiketoHearfromYou
Wehavegonethroughseveralstagesofproofreadinganderrorchecking
duringtheproductionofthisbookinanefforttoreducethenumberof
errors.Wehavealsotriedtomaketheexamplesandtheexplanationsas

clearaspossible.
Theremay,however,stillbeerrorsandunclearareasinthisbook.Ifyou
havequestionsorfindanyoftheseerrors,pleasefeelfreetocontactme
atYoucanalsovisittheApresswebsiteat
todownloadcodefromthebookandseeany
availableerrata.


Chapter1:IntroducingtheBasicsofAutomation


Overview
WhenIwasinhighschool,Igotmyfirstpart-timejobkeepingsomeof
theschool'scomputersrunning.Itwasgreat.Idideverythingbyhand.
Andsincetherewereonlytwoorthreecomputers,doingeverythingby
handwasn'tabigissue.Buteventhen,asthenumberofsystemsgrew
tofive,six,andfinallymorethanten,Irealizedjusthowmuchtimeyou
canspenddoingthesamethingsoverandoveragain.Thisishowmy
loveofautomationwasborn.
Inthischapteryouwilllearnthebasicsofautomatingsystem
administrationsothatyoucanbegintomakeyourlifeeasier—aswellas
thelivesofeverybodywhousesordependsonyoursystems.Thetopics
coveredinthisbookareapplicabletoawidevarietyofsituations.
Whetheryouhavethousandsofisolatedsystems(soldtoyour
customers,forexample),alargenumberofdiversemachines(alarge
companyoruniversitycampus),orjustafewserversinyourhomeor
smallbusiness,most,ifnotall,ofthetechniquescoveredwillsaveyou
timeandmakeyouabetteradministrator.
Throughoutthisbook,Ihaveassumedthatthereaderhasabasicsetof
UNIXskillsandsomepriorexperienceasasystemsadministrator.Iused

numeroustoolsthroughoutthebooktoprovideexampleautomation
solutions.Thesetoolsincludethefollowing:
Thebashshell
Perl
Regularexpressions
Thegrepcommand
ThesedStreamEditor
awk
Ifyouarenotveryfamiliarwithoneormoreofthesetools,Iurgeyouto


×