Advertisement
Guest User

snapshot_remove.rb

a guest
Aug 21st, 2014
544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.88 KB | None | 0 0
  1. #!/usr/bin/ruby1.9.1
  2.  
  3. snapshots = []
  4. keep_snaps = []
  5. remove_snaps = []
  6.  
  7. all_snaps = `echo ubuntu1234 | sudo -S lvscan`
  8.  
  9. all_snaps.split("inherit\n").each do |shot|
  10.   if shot.include?("rootfs_12.10") && shot.include?("Snapshot")
  11.       puts "Found snapshots are--> #{shot}"
  12.       snapshots << shot.strip.chomp
  13.   end
  14. end
  15.  
  16. remove_snaps = snapshots.dup
  17. keep_snaps = remove_snaps.slice!(-1..-1)
  18.  
  19. unless remove_snaps.empty?
  20.   remove_snaps.each do |snap|
  21.      snap_name = snap.split("ACTIVE   Snapshot '").last.split("' [1.00 GiB]").first.strip.chomp
  22.      `/usr/bin/expect <<delim
  23.     exp_internal 0
  24.     set timeout 20
  25.     spawn sudo lvremove #{snap_name}
  26.     expect "*password for ubuntu:"
  27.     send "ubuntu1234\n"
  28.     expect "Do you really want to remove active logical volume*"
  29.     send "y\n"
  30.     expect eof
  31.    delim`
  32.     puts "We have removed #{snap_name}"
  33.   end
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement