Unix shell scripting with ksh/bash

Combine lengthy and repetitive sequences of commands into a single, simple command.

#!/bin/sh

BACKUPDIR=/backup

YESTERDAY=`ls -1t $BACKUPDIR | sed -n 1p`

if [ -n "$YESTERDAY" ] ; then
    ls -lt $BACKUPDIR/$YESTERDAY > /tmp/backup_status.txt
    if [ -s /tmp/backup_status.txt ]; then
	mail -s "Backup Status $YESTERDAY" -c "sale@bangtech.com" webmaster@bangtech.com < /tmp/backup_status.txt
    else
	mail -s "Backup Status $YESTERDAY" -c "sale@bangtech.com" webmaster@bangtech.com < /tmp/backup_status.txt
    fi
fi