I use the following script to archive and delete user accounts.
The script expects a list of names as $1, but I'd like to have the script stop immediately if that first argument does not exist, and inform user with correct usage.
Your suggestions and any other improvements most appreciated!
Thanks, Dan
#!/bin/bash
PATH=/bin:/usr/bin:/sbin:/usr/sbin export PATH
DESTDIR='/Volumes/UserStorage/Backups'
SRCDIR='/Volumes/UserStorage/Users'
LOG=`mktemp -t archive-accounts-XXXXX.log`
EMAIL_FROM='admin@example.com'
EMAIL_TO='admin@example.com'
EMAIL_SUBJ='Account archiving batch job report'
{
echo "Batch Begins...`date`"
echo "###############"
echo " "
while IFS= read -r line
# If not first argument, script should exit with usage message
do
echo Starting account $line
hdiutil create $DESTDIR/$line-$(date +%d-%m-%y).dmg -srcfolder $SRCDIR/$line
RETCODE=$?
if [ $RETCODE -eq 0 ]; then
STATUS="Success"
# rm -rf $SRCDIR/$line
else
STATUS="FAILED!"
fi
echo Exit Status: $STATUS
echo Finished with account $line
echo ""
done < $1
echo "###############"
echo "Batch complete! `date`"
} >> $LOG 2>&1
cat $LOG | mailx -s "$EMAIL_SUBJ" $EMAIL_TO
exit 0