Skip to content

Instantly share code, notes, and snippets.

@cbare
Last active April 21, 2020 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cbare/4180915 to your computer and use it in GitHub Desktop.
Save cbare/4180915 to your computer and use it in GitHub Desktop.
create a new directory and put a checkpoint in it
#!/usr/bin/python
# crontab -e
# */20 * * * * /home/ubuntu/checkpoint.py > /home/ubuntu/checkpoint.log 2>&1
import os
hosts = []
with open('/usr/local/Rmpi/hostfile.plain') as f:
for line in f:
hosts.append(line.split()[0])
os.chdir("/home/ubuntu/large1")
if os.path.exists('checkpoint_counter'):
with open('checkpoint_counter') as f:
i = int(f.read())
else:
i = 1
try:
os.mkdir("checkpoint%d" % i)
os.chdir("checkpoint%d" % i)
for host in hosts:
print('scp -i ~/cbare-sage.pem ubuntu@%s:/home/ubuntu/dose.large.node*.tsv .' % host)
os.system('scp -i ~/cbare-sage.pem ubuntu@%s:/home/ubuntu/dose.large.node*.tsv .' % host)
os.chdir('..')
with open("checkpoint_counter", "w") as f:
f.write("%d\n" % (i+1))
except Exception, e:
print("Error: " + str(e))
finally:
os.chdir("/home/ubuntu/")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment