January 2004
Intermediate to advanced
368 pages
7h 25m
English
This script is an example of an entire class of useful shell scripts called wrappers. The basic idea of wrappers is that they live between an actual Unix command and the user, offering the user different and useful functionality not available with the actual command alone. In the case of this script, file deletions using the rm command will actually be logged in a separate log file without notifying the user.
#!/bin/sh # logrm - Logs all file deletion requests unless the -s flag is used. removelog="/var/log/remove.log" if [ $# -eq 0 ] ; then echo "Usage: $0 [-s] list of files or directories" >&2 exit 1 fi if [ "$1" = "-s" ] ; then # silent operation requested ... don't log shift else echo "$(date): ${USER}: ...Read now
Unlock full access