unkwntech

Secure file Erase

Aug 21st, 2012
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.33 KB | None | 0 0
  1. TARGET=$1
  2.  
  3. if [ -z $TARGET ];
  4. then
  5.         echo "You must specify a file to destroy";
  6. else
  7.         if [ ! -w $TARGET ];
  8.         then
  9.                 echo "Cannot write target file, do you have permissions?";
  10.         else
  11.                 SIZE=`stat -c%s $TARGET`;
  12.                 URL="http://www.random.org/cgi-bin/randbyte?nbytes=$SIZE&format=f"
  13.  
  14.  
  15.                 if [ $SIZE -lt 1 ];
  16.                 then
  17.                         echo "ERROR: Unable to stat file";
  18.                 else
  19.  
  20.                         if [ -z $2 ];
  21.                         then
  22.                                 ITERATIONS=32;
  23.                         else
  24.                                 ITERATIONS=$2
  25.                         fi
  26.  
  27.                         echo "Killing $TARGET; FileSize $SIZE; $ITERATIONS iterations";
  28.  
  29.                         for i in `seq 1 $ITERATIONS`;
  30.                         do
  31.                                 (curl $URL > ./rand) 2>/dev/null
  32.                                 dd if=./rand of=$TARGET bs=1 count=$SIZE 2>/dev/null;
  33.                                 rm -f ./rand;
  34.                                 echo "Iteration $i Finished";
  35.                         done
  36.  
  37.                         dd if=/dev/zero of=$TARGET bs=1 count=$SIZE 2>/dev/null;
  38.  
  39.                         rm -f $TARGET;
  40.                 fi
  41.         fi
  42. fi
Advertisement
Add Comment
Please, Sign In to add comment