matlab: FindFreeSSH allow hostfile

pull/1/head
Thorsten Liebig 2011-11-24 09:00:13 +01:00
parent 7ef80834cb
commit eb769052a2
1 changed files with 26 additions and 5 deletions

View File

@ -11,7 +11,7 @@ function host = FindFreeSSH(host_list, wait_time, command)
% default: 600 seconds % default: 600 seconds
% %
% command: unix command to check for free host (empty result --> free) % command: unix command to check for free host (empty result --> free)
% default: 'ps -ewwo user,args | grep openEMS' % default: 'ps -e | grep openEMS'
% %
% See also RunOpenEMS % See also RunOpenEMS
% %
@ -28,17 +28,38 @@ if (nargin<2)
wait_time = 600; wait_time = 600;
end end
while 1 if ischar(host_list)
fid=fopen(host_list);
if (fid==-1)
error('FindFreeSSH: cant open host file');
end
clear host_list;
host_list = {};
while 1
line = fgetl(fid);
if ischar(line)
host_list{end+1} = line;
else
break;
end
end
fclose(fid);
elseif ~iscell(host_list)
error('FindFreeSSH: unknown host list format');
end
while 1
for n = 1:numel(host_list) for n = 1:numel(host_list)
host = host_list{n}; host = host_list{n};
[status, result] = unix(['ssh ' host ' ' command]); [status, result] = unix(['ssh ' host ' ' command]);
if isempty(result) if (isempty(result) && status==1)
disp(['FindFreeSSH:: found a free host: ' host ]); disp(['FindFreeSSH:: found a free host: ' host ]);
return return
else elseif (~isempty(result) && status==0)
disp(['FindFreeSSH:: ' host ' is busy running openEMS ... ' ]); disp(['FindFreeSSH:: ' host ' is busy running openEMS ... ' ]);
else
disp(['FindFreeSSH:: shh connection to ' host ' failed ... ' ]);
end end
end end