Hour 22

1: Add a check to the sshd init script that verifies if the user is root. (Init scripts should only be executed by root).

HINT: Use the id and sed commands.

A1: You can add a check similar to the following to the beginning of the init script:
CURUID="`id | sed -e 's/(.*$//' -e 's/^.*\=//'`"
if [ "$CURUID" -ne 0 ] ; then
    echo "Error: Only root (uid=0) can run this script." 1>&2
    exit 1
fi
unset CURUID
2: The showperson script lists all matching entries in the address book based on a name provided by the user. The matches produced are case sensitive. How can you change the script matches so they aren't case sensitive?
A2: Use grep -i instead of grep.
3: Both the showperson and delperson scripts reproduce the following code
 PATH=/bin:/usr/bin ...

Get Sams Teach Yourself Shell Programming in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.