0001 function [remotehome] = reminstall(remote)
0002
0003
0004
0005 disp('-------------------------------------------------------')
0006 disp('---- setting folders and files for testremotebatch ----')
0007 disp('-------------------------------------------------------')
0008
0009 remotehost = remote.host;
0010
0011
0012
0013 [res,logname] = unix('whoami');
0014
0015 if res ~= 0,
0016 error('Local login name could not be obtained')
0017 end
0018
0019
0020
0021 logname(double(logname) == 10) = [];
0022
0023 if isfield(remote,'users') && isfield(remote.users,logname) && ~isempty(remote.users.(logname)),
0024 remotelogname = remote.users.(logname);
0025 else
0026 remotelogname = logname;
0027 end
0028
0029 remotecmd = 'echo $HOME';
0030
0031 if ~isempty(remotehost),
0032
0033 [res,remotehome] = unix(['ssh ',remotelogname,'@',remotehost,' ''',remotecmd,'''']);
0034
0035 else
0036
0037 [res,remotehome] = unix(remotecmd);
0038
0039 end
0040
0041 if res ~= 0,
0042 error(['File transfer failed : ',remotehome])
0043 end
0044 disp(' ... done');
0045 remotehome(double(remotehome) == 10) = [];
0046
0047
0048
0049 remotedirtest_jd(remotehost,remotelogname,[remotehome,filesep,'remotebatchtest/'])
0050 pause(2);
0051 remotedirtest_jd(remotehost,remotelogname,[remotehome,filesep,'remotebatchtest/bin/'])
0052 pause(2);
0053 remotedirtest_jd(remotehost,remotelogname,[remotehome,filesep,'remotebatchtest/mat/'])
0054 pause(2);
0055
0056
0057
0058
0059 filename = which('matlabbatch.sh');
0060 ifilesep = strfind(filename,filesep);
0061 local_path = filename(1:ifilesep(end));
0062 filename = filename(ifilesep(end)+1:end);
0063 remotefilecopy_jd(remotehost,remotelogname,local_path,filename,[remotehome,filesep,'remotebatchtest/bin/'])
0064
0065 filename = 'remotetest.m';
0066 local_path = [pwd,'/'];
0067 remotefilecopy_jd(remotehost,remotelogname,local_path,filename,[remotehome,filesep,'remotebatchtest/mat/'])
0068
0069 filename = which('remotematrun.m');
0070 ifilesep = strfind(filename,filesep);
0071 local_path = filename(1:ifilesep(end));
0072 filename = filename(ifilesep(end)+1:end);
0073 remotefilecopy_jd(remotehost,remotelogname,local_path,filename,[remotehome,filesep,'remotebatchtest/mat/'])
0074
0075 filename = which('runmat.m');
0076 ifilesep = strfind(filename,filesep);
0077 local_path = filename(1:ifilesep(end));
0078 filename = filename(ifilesep(end)+1:end);
0079 remotefilecopy_jd(remotehost,remotelogname,local_path,filename,[remotehome,filesep,'remotebatchtest/mat/'])
0080
0081 disp('-------------------------------------------------------')
0082 disp('-------------------- setting done ---------------------')
0083 disp('-------------------------------------------------------')
0084
0085 end
0086
0087 function remotedirtest_jd(remotehost,remotelogname,location)
0088
0089
0090
0091 disp(['testing if the remote folder ',location,'exists'])
0092 remotecmd = ['test -d ',location];
0093
0094 if ~isempty(remotehost),
0095 res = unix(['ssh ',remotelogname,'@',remotehost,' ''',remotecmd,'''']);
0096 else
0097 res = unix(remotecmd);
0098 end
0099
0100
0101
0102 if res == 1,
0103 remotecmd = ['mkdir ',location];
0104 disp([' --> Creating remote data folder ',location])
0105 if ~isempty(remotehost),
0106 [res,err] = unix(['ssh ',remotelogname,'@',remotehost,' ''',remotecmd,'''']);
0107 else
0108 [res,err] = unix(remotecmd);
0109 end
0110 if res ~= 0,
0111 error(['Remote data folder creation failed : ',err])
0112 end
0113 disp(' ... done');
0114 end
0115 end
0116
0117 function remotefilecopy_jd(remotehost,remotelogname,local_path,filename,remote_path)
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149 remotecmd = ['chmod a+x ',remote_path,filename];
0150
0151 if ~isempty(remotehost),
0152
0153 disp([' --> Copying script file ',local_path,filename,' to remote host ',remotehost,':',remote_path,' as user ',remotelogname,' ...'])
0154 [res,err] = scp2remote_yp(remotelogname,remotehost,filename,local_path,remote_path);
0155 [res2,txt2] = unix(['ssh ',remotelogname,'@',remotehost,' ''',remotecmd,'''']);
0156
0157 else
0158
0159 disp([' --> Copying script file ',local_path,filename,' to ',remote_path]) ;
0160 [res,err] = unix(['cp ',local_path,filename,' ',remote_path]);
0161 [res2,txt2] = unix(remotecmd);
0162
0163 end
0164
0165 if res ~= 0,
0166 error(['File transfer failed : ',err])
0167 end
0168 disp(' ... done');
0169 end
0170
0171
0172