Skip to content

Instantly share code, notes, and snippets.

@maluta
Created July 22, 2011 19:33
Show Gist options
  • Save maluta/1100234 to your computer and use it in GitHub Desktop.
Save maluta/1100234 to your computer and use it in GitHub Desktop.
dd wrapper to avoid mistakes
#!/usr/bin/python
import sys
import subprocess
def usage():
return " \n Misssing config file, you must create a file called ~/.blocklist-dd and insert which device dd should avoid \n\n \
Ex: \n \
$ echo \"/dev/sda\" > ~/.blocklist-dd \n \
$ echo \"/dev/sdb\" >> ~/.blocklist-dd \n \
"
try:
f = open("~/.blocklist-dd","r")
except:
print usage()
sys.exit(0)
pattern = f.readlines()
f.close()
for p in pattern:
for param in sys.argv:
if param.find(p[:-1]) != -1:
print "ooops, you are associating a blocked device (%s) on dd, proceed? (Y/n) (Y/n)" % p[:-1]
op = raw_input()
if op != "Y":
sys.exit(0)
sys.argv[0] = "dd"
subprocess.call(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment