# Thu Aug 8 16:32:47 CEST 2013 # jasper kursk # # this is a module file that connects to fermi via ssh and calls another script there, that extracts data and copies it back to the scratch of the user. rewrites the copied file each time # # probably wont get changed much, unless i want to clean it up, which it probably could use import subprocess import getpass import sys import os sys.path.append('/usr/lib/python2.4/site-packages/') import pexpect def write_file(x,y,z, username, password): fermi_h = username + "@login.fermi.cineca.it" plx_h = username + "@login.plx.cineca.it" plx_home = "/plx/userexternal/" + username + "/" #scratch = "/gpfs/scratch/userexternal/" + username + "/" if 'CINECA_SCRATCH' not in os.environ: print "oma kodu ei leia ma yles" quit() scratch = os.environ['CINECA_SCRATCH'] + "/" if x < 1: x = 1 elif x > 128: x = 128 else: x = int(x) if y < 1: y = 1 elif y > 128: y = 128 else: y = int(y) if z < 1: z = 1 elif z > 128: z = 12 else: z = int(y) #child = pexpect.spawn('ssh jkursk00@login.fermi.cineca.it nohup python write_file2.py '+ str(x) + ' ' + str(y) + ' ' + str(z)) #child = pexpect.spawn('ssh ' + fermi_h +' nohup python /fermi/home/userexternal/jkursk00/write_file2.py '+ str(x) + ' ' + str(y) + ' ' + str(z) + ' ' + scratch) child = pexpect.spawn('ssh ' + fermi_h +' nohup python write_file2.py '+ str(x) + ' ' + str(y) + ' ' + str(z) + ' ' + scratch) child.timeout = 90 i = child.expect([ fermi_h+"'s password: "], timeout = 90) if i == 0: child.sendline(password) else: print "failed at sending a password to fermi :(" return None i = child.expect(["vtk file created","Permission denied, please try again."], timeout = 90) if i == 0: #child = pexpect.spawn('scp jkursk00@login.fermi.cineca.it:~/file_'+ str(x) + '_' + str(y) + '_' + str(z) + '.vtk /plx/userexternal/jkursk00/') #i = child.expect(["jkursk00@login.fermi.cineca.it's password: "]) #child = pexpect.spawn('scp '+ fermi_h +':~/file_'+ str(x) + '_' + str(y) + '_' + str(z) + '.vtk '+plx_home) child = pexpect.spawn('scp '+ fermi_h +':'+ scratch +'asciidata.vtk '+scratch) i = child.expect([ fermi_h+"'s password: "], timeout = 90) if i == 0: child.sendline(password) child.readlines() elif i == 1: print "incorrect username/password!" return None else: print "something broke :(" return None return scratch + 'asciidata.vtk'