Skip to Content
Essential System Administration, 3rd Edition
book

Essential System Administration, 3rd Edition

by Æleen Frisch
August 2002
Beginner
1176 pages
36h 52m
English
O'Reilly Media, Inc.
Content preview from Essential System Administration, 3rd Edition

Creating Effective Shell Scripts

In this section, we’ll consider several different routine system administration tasks as examples of creating and using administrative shell scripts. The discussions are meant to consider not only these tasks in themselves but also the process of writing scripts. Most of the shell script examples use the Bourne shell, but you can use any shell you choose; it’s merely a Unixprejudice that “real shell programmers use the Bourne/Korn/zsh shell,” however prevalent that attitude/article of faith may be.[1]

Password File Security

We discussed the various security issues surrounding the password file in Section 7.8 and Section 6.1. The various commands used to check it and its contents could be combined easily in a shell script. Here is one version (named ckpwd):

#!/bin/sh # ckpwd - check password file (run as root) # # requires a saved password file to compare against: # /usr/local/admin/old/opg # umask 077 PATH="/bin:/usr/bin"; export PATH cd /usr/local/admin/old # stored passwd file location echo ">>> Password file check for `date`"; echo "" echo "*** Accounts without passwords:" grep '^[^:]*::' /etc/passwd if [ $? -eq 1 ] # grep found no matches then echo "None found." fi echo "" # Look for extra system accounts echo "*** Non-root UID=0 or GID=0 accounts:" grep ':00*:' /etc/passwd | \ awk -F: 'BEGIN {n=0} $1!="root" {print $0 ; n=1} END {if (n==0) print "None found."}' echo "" sort </etc/passwd >tmp1 sort <opg >tmp2 # opg is the previously saved copy ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Unix® and Linux® System Administration Handbook, Fourth Edition

Unix® and Linux® System Administration Handbook, Fourth Edition

Evi Nemeth, Garth Snyder, Trent R. Hein, Ben Whaley

Publisher Resources

ISBN: 0596003439Errata Page