Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Replacement script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Replacement script
Authored by: derekhed on Oct 06, '04 03:28:05PM
I accidentally left my cron entry to run this script after I ejected my black CD. I forgot all about it until I noticed a dozen or so CRON, sh, and hdiutil entries in my ps list.
I rewrote the script, wrapping everything inside a check for the existence of writable CD media. The next version could include a test for free space on the CD after creating the disk image. So here it is, version 1.01:

# Back up logs to a CD incrementally. Saves as 'log n' in reverse order,
# renaming each as a higher increment and laying down a new file 'log'
# How the hell does it do this?
# Wrap the whole process in a test for CD Media

if drutil status | grep -i "No Media Inserted" > /dev/null 2>&1
      echo "No Media found. Failing."
      echo "Media found"
      # No luck with appendable, but you could try adding it.
      if drutil status | egrep "overwritable|blank" > /dev/null 2>&1
         echo "Medium is writable"
         # May as well use a timestamp for our temp file.
         stamp=`date +%y%m%d-%H%M%S`

         # Create the image
         hdiutil create -quiet -srcfolder /var/log/ /tmp/Log_$stamp.dmg

         # Wait for it...?
         sleep 5
         # Now burn the image
         hdiutil burn -quiet /tmp/Log_$stamp.dmg -noeject
         # Clean up after yourself
         rm /tmp/Log_$stamp.dmg
         # Let the drive mount. 15 works for me, but yours may be different.
         sleep 25
         # Report back to cron how much space is used.
         free=`du -ch /Volumes/log* | grep -i Total`
         echo "$free used on log Backup CD"
         echo "Can't write to CD Medium. Failing."
      fi # End check for writable Media
fi # End check for inserted Media

[ Reply to This | # ]