#!/usr/bin/ruby
DVD_SIZE=4294967296
CD_SIZE=734003200
size_limit=CD_SIZE
archive_id=1000+rand(10000)
datestamp=Time.now.strftime('%Y-%m-%d %H:%M')
too_big=false
files=(%x{ls -l}).split("\n")
files=files.collect{|f|
if (f[/wav/].nil?)
nil
else
fn=f[53..-1]
{'filesize'=>f[31..(31+8)].to_i,
'filename'=>fn,
'identifier'=>fn[0..-5]}
end
}.compact
i=0
total_archived=0
continue_burning=true
while continue_burning
while !too_big
file=files[i]
#copy the file to the archive directory
`cp #{file['filename']} archive`
#echo "Archive 07/23/08-1" to the file
`echo "Archive #{datestamp}-#{archive_id}" > #{file['filename']}`
#rename the file to filename.place
n `mv #{file['filename']} #{file['identifier']}.archived`
#check the size of the archive directory
total_archived+=file['filesize']
puts "Current archive size #{total_archived}. #{total_archived/1024/1024/1024} GB file #{i}."
too_big=true if (total_archived>size_limit)
i=i+1
end
puts "Done archiving"
#burn the archive directory
`bash /var/spool/asterisk/monitr/burn.sh`
puts "Please label the disk #{datestamp} - #{archive_id} (Eject if necessary)"
`eject /dev/dvd`
#prompt the user if the program should make another disc
puts %x{df}
puts "Continue archiving? [y/n]"
choice=gets.chomp
if choice=='n'
continue_burning=false
else
puts "Please insert another disc, type 'go' when done"
ready=gets
totalarchived=0
too_big=false
end
end
Refactorings
No refactoring yet !
Originally made to move call recordings off an asterisk server's recordings directory. Replaces the file with a place holder indicating the # of the DVD containing the recording.