source: issm/branches/trunk-jpl-damage/src/m/utils/OS/issmssh.py@ 12878

Last change on this file since 12878 was 12878, checked in by cborstad, 13 years ago

merged trunk-jpl into trunk-jpl-damage through revision 12877

File size: 1.2 KB
Line 
1import socket
2import platform
3import subprocess
4import os
5from MatlabFuncs import *
6
7def issmssh(host,login,port,command):
8 """
9 ISSMSSH - wrapper for OS independent ssh command.
10
11 usage:
12 issmssh(host,command)
13 """
14
15 #first get hostname
16 hostname=socket.gethostname().lower().split('.')[0]
17
18 #if same as host, just run the command.
19 if strcmpi(host,hostname):
20 subprocess.call(command,shell=True)
21 else:
22 if 'Windows' in platform.system():
23 #use the putty project plink.exe: it should be in the path.
24
25 #get ISSM_DIR variable
26 if 'ISSM_DIR_WIN' in os.environ:
27 ISSM_DIR=os.environ['ISSM_DIR_WIN'][1:-2]
28 else:
29 raise OSError("issmssh error message: could not find ISSM_DIR_WIN environment variable.")
30
31 username=raw_input('Username: (quoted string) ')
32 key=raw_input('Key: (quoted string) ')
33
34 subprocess.call('%s/externalpackages/ssh/plink.exe -ssh -l "%s" -pw "%s" %s "%s"' % (ISSM_DIR,username,key,host,command),shell=True);
35
36 else:
37 #just use standard unix ssh
38 if port:
39 subprocess.call('ssh -l %s -p %d localhost "%s"' % (login,port,command),shell=True)
40 else:
41 subprocess.call('ssh -l %s %s "%s"' % (login,host,command),shell=True)
42
Note: See TracBrowser for help on using the repository browser.