reminstall

PURPOSE ^

SYNOPSIS ^

function [remotehome] = reminstall(remote)

DESCRIPTION ^

 This function transfers and copies functions for testremotebatch

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [remotehome] = reminstall(remote)
0002 %
0003 % This function transfers and copies functions for testremotebatch
0004 %
0005 disp('-------------------------------------------------------')
0006 disp('---- setting folders and files for testremotebatch ----')
0007 disp('-------------------------------------------------------')
0008 %
0009 remotehost = remote.host;%  hostname (empty for local host)
0010 %
0011 % get local user name
0012 %
0013 [res,logname] = unix('whoami');
0014 %
0015 if res ~= 0,
0016     error('Local login name could not be obtained')
0017 end
0018 %
0019 % get remote user name
0020 %
0021 logname(double(logname) == 10) = [];% remove return character
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),%remote calculation
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) = [];% remove return character
0046 %
0047 % check if directories exist - create them if needed
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 % copy test files into directory
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     % test if folder exists
0090     %
0091     disp(['testing if the remote folder ',location,'exists'])
0092     remotecmd = ['test -d ',location];% test if remote directory exists
0093     %
0094     if ~isempty(remotehost),
0095         res = unix(['ssh ',remotelogname,'@',remotehost,' ''',remotecmd,'''']);
0096     else
0097         res = unix(remotecmd);
0098     end
0099     %
0100     % create folder if needed
0101     %
0102     if res == 1,% remote directory does not exist
0103         remotecmd = ['mkdir ',location];%create remote directory
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 %     % test if file exists.
0120 %     %
0121 %     disp(['testing if the remote file ',location,filename,'exists'])
0122 %     remotecmd = ['test -f ',remote_path,filename];% test if remote directory exists
0123 %     %
0124 %     if ~isempty(remotehost),
0125 %         res = unix(['ssh ',remotelogname,'@',remotehost,' ''',remotecmd,'''']);
0126 %     else
0127 %         res = unix(remotecmd);
0128 %     end
0129 %     %
0130 %     % delete remote files if they exist
0131 %     %
0132 %     if res == 0,% remote file does exist
0133 %         remotecmd = ['rm ',remote_path,filename];%create remote directory
0134 %         disp(['    --> Deleting remote file ',remote_path,filename])
0135 %         if ~isempty(remotehost),
0136 %             [res,err] = unix(['ssh ',remotelogname,'@',remotehost,' ''',remotecmd,'''']);
0137 %         else
0138 %             [res,err] = unix(remotecmd);
0139 %         end
0140 %         if res ~= 0,
0141 %             error(['Remote file deletion failed : ',err])
0142 %         end
0143 %         disp(' ... done');
0144 %     end
0145     %
0146     % copy file into destimation
0147     %
0148     %
0149     remotecmd = ['chmod a+x ',remote_path,filename];
0150     %
0151     if ~isempty(remotehost),%remote calculation
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

Community support and wiki are available on Redmine. Last update: 18-Apr-2019.