Skip to content

Instantly share code, notes, and snippets.

@benguillet
Last active December 15, 2015 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benguillet/5190447 to your computer and use it in GitHub Desktop.
Save benguillet/5190447 to your computer and use it in GitHub Desktop.
A Django gist to send a text file and launch a program on a different server
if request.method == 'POST':
if form.is_valid():
# write file in ~/hipercic/apps/dcor/jobs/
with open('apps/dcor/jobs/job_' + datetime.today().strftime("%Y%m%d_%H%M%S") + '_params.txt', 'w') as params_file:
for key, val in form.cleaned_data.iteritems():
params_file.write(str(val) + ' \n')
scp = 'scp /home/guillet/hipercic/' + params_file.name + ' guillet@helios.public.stolaf.edu:dcor/jobs/'
context['scp'] = scp
return_code_scp = subprocess.call(scp, shell=True)
context['return_code_scp'] = return_code_scp
head, tail = os.path.split(params_file.name)
print tail
cpp = 'ssh guillet@helios.public.stolaf.edu "cd dcor; ./test jobs/' + tail + '"'
context['cpp'] = cpp
return_code_cpp = subprocess.call(cpp, shell=True)
context['return_code_cpp'] = return_code_cpp
return render(request, 'base_pending.html', context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment