Linux服务器清空

 

  
  
  
  
  1. #!/bin/bash 
  2. # This script will absolutely kill a RHEL/CentOS/Fedora server. Use with extreme caution. 
  3. # Tested with several CentOS/RHEL versions only. Run as root user. 
  4. # 10.20.11 Paul Venezia ([email protected]
  5.  
  6. zeroscript="/var/ramdisk/zeroscript.sh" 
  7.  
  8. echo "******************************************************************* 
  9. ** This will permanently kill this Linux system and erase every  ** 
  10. ** local disk and filesystem. In other words, you better be      ** 
  11. ** REALLY REALLY SURE you want to do this on this system.        ** 
  12. *******************************************************************" 
  13. echo -n "Are you absolutely sure you want to do this? [yes|no]: "; read yn 
  14.  
  15. if [ -z $yn ] || [ $yn != "yes" ]; then 
  16. echo "Aborting" 
  17. exit 1 
  18. fi 
  19.  
  20. echo -n "How many zeroing passes? "; read zeropass 
  21. if [ -z $zeropass ] || [ $zeropass -lt 1 ]; then 
  22. echo "Invalid number of passes specified. Aborting." 
  23. exit 1 
  24. fi 
  25.  
  26. echo -n "Automatically shutdown? [yes|no] "; read asd 
  27. echo "Okay, here we go..." 
  28. echo "Making and populating ramdisk (512MB)..." 
  29. mkdir -p /var/ramdisk 
  30. mount -t tmpfs none /var/ramdisk -o size=512m # You may need to adjust this depending on the amount of RAM in the box 
  31. mkdir -p /var/ramdisk/var/run 
  32.  
  33. for f in dev bin lib lib64 sbin etc; do  
  34. cp -pr /$f /var/ramdisk 
  35. done 
  36.  
  37. cp -pr /var/run /var/ramdisk/var 
  38.  
  39. echo "Stopping services, it's probably safe to ignore any errors..." 
  40.  
  41. for s in httpd acpid anacron atd auditd autofs avahi-daemon bluetooth cpuspeed crond cups firstboot gpm haldaemon hidd hplip irqbalance iscsi iscsid kudzu lm_sensors lvm2-monitor mcstrans mdmonitor messagebus microcode_ctl netfs nfslock pcscd portmap rawdevices readahead_early restorecond rpcgssd rpcidmapd sendmail smartd sshd syslog vmware-tools xfs yum-updatesd; do 
  42. service $s stop 
  43. done 
  44.  
  45. echo "Placing zeroing script..." 
  46. echo "#!/bin/bash" > $zeroscript 
  47.  
  48. for i in `fdisk -l | grep Disk | awk '{print$2}' | sed -e s/:// | grep -v /dev/md`; do 
  49. DU=$DU" "$i 
  50. DSK=`basename $i` 
  51.         BLKS=$((`grep -w $DSK /proc/partitions | awk '{print$3}'` * 2)) # account for 512/1k blocksizes 
  52.         BS=512 
  53.         echo "echo \"Zeroing $i (dd if=/dev/zero of=$i bs=$BS count=$BLKS) ...\"" >> $zeroscript 
  54. for (( c=1; c<=$zeropass; c++ )); do 
  55. echo "echo \"Pass $c...\"" >> $zeroscript 
  56.         echo "dd if=/dev/zero of=$i bs=$BS count=$BLKS" >> $zeroscript 
  57. done 
  58.         echo "dd if=/dev/zero of=$i bs=512 count=1>> $zeroscript # Just to make sure 
  59. done 
  60. echo "echo \"Disk(s)$DU have been zeroed $zeropass times\"" >> $zeroscript 
  61. if [ $asd = 'yes' ]; then 
  62. echo "echo \"Shutting down...\"" >> $zeroscript 
  63. echo "sleep 5 && /sbin/poweroff -n -d -f" >> $zeroscript 
  64. fi 
  65. chmod +x $zeroscript 
  66. echo "Turning off swap..." && swapoff -a 
  67. echo "Entering chroot..." 
  68. chroot /var/ramdisk /`basename $zeroscript` 

 

你可能感兴趣的:(linux,服务器清空)