Skip to content

Instantly share code, notes, and snippets.

@alxrogan
Created October 4, 2011 15:00
Show Gist options
  • Save alxrogan/1261863 to your computer and use it in GitHub Desktop.
Save alxrogan/1261863 to your computer and use it in GitHub Desktop.
Create an .iso file from .zip files, then burn those files to a CDROM using multi-session
#!/bin/bash
# Created by Aaron, 12-29-2003
# This script is meant to create an .iso file from .zip files, then burn those files to a CDROM using multi-session
# Future upgrades: Research the use of a try/catch style function call so that a bad program can't hang the script indefinitely.
# Updated on 01-05-2004 to include support for multi-session CDROM burning
TRACK=`cdrecord -msinfo dev=ATAPI:0,1,0`
if ! [ $TRACK ]
then
# Track is null, therefore new CD, create standard ISO.
mkisofs -r -J -log-file ~backup_audit/logs/backup-log-`date +%m-%d-%y`.log -o ~backup_audit/backup-log-`date +%m-%d-%y`.iso ~backup_audit/[Ss]ecurity*.zip
else
# Track is NOT null, therefore create multisession ISO.
mkisofs -r -J -C $TRACK -M /dev/cdrom -log-file ~backup_audit/logs/backup-log-`date +%m-%d-%y`.log -o ~backup_audit/backup-log-`date +%m-%d-%y`.iso ~backup_audit/[Ss]ecurity*.zip
fi
# Rudimentary error checking, if the ISO created, move forward and log, else error and log.
if [ -f ~backup_audit/backup-log-`date +%m-%d-%y`.iso ]
then
echo "-----" >> ~backup_audit/logs/backup-log-`date +%m-%d-%y`.log
echo "ISO file created" >> ~backup_audit/logs/backup-log-`date +%m-%d-%y`.log
echo "-----" >> ~backup_audit/logs/backup-log-`date +%m-%d-%y`.log
cdrecord -multi dev=ATAPI:0,1,0 speed=10 -v ~backup_audit/backup-log-`date +%m-%d-%y`.iso >> ~backup_audit/logs/backup-log-`date +%m-%d-%y`.log
# If the cdrecord returns a 0 error code, then it burned successfully, move the log files to a temporary holding location, log and exit.
if [ $? = 0 ]
then
mv ~backup_audit/[Ss]ecurity*.zip ~backup_audit/burned_backup_logs
rm -f ~backup_audit/backup-log-`date +%m-%d-%y`.iso
echo "-----" >> ~backup_audit/logs/backup-log-`date +%m-%d-%y`.log
echo "Files successfully burned on `date +%m-%d-%y` at `date +%H:%M:%S`." >> ~backup_audit/logs/backup-log-`date +%m-%d-%y`.log
else
# More rudimentary error checking, if an error code was returned, it is likely that a fixated/closed disc was loaded in the drive, so log and exit.
echo "An error occurred on `date +%m-%d-%y` at `date +%H:%M:%S`, files were not burned. Check that blank recordable media is present in the drive." >> ~backup_audit/logs/backup-log-`date +%m-%d-%y`.log
fi
else
# If there was no ISO created, chances are that the files were not present, like on a weekend, or over a holiday, when they wouldn't normally send files. Therefore, it can exit gracefully on an error condition, very important for a script that is run as a cron job without any interaction.
echo "An error occurred on `date +%m-%d-%y` at `date +%H:%M:%S`, log files were not present." >> ~backup_audit/logs/backup-log-`date +%m-%d-%y`.log
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment