From eb769052a2417c8cfb40083a6a3b5b20fdb91e4f Mon Sep 17 00:00:00 2001 From: Thorsten Liebig Date: Thu, 24 Nov 2011 09:00:13 +0100 Subject: [PATCH] matlab: FindFreeSSH allow hostfile --- matlab/FindFreeSSH.m | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/matlab/FindFreeSSH.m b/matlab/FindFreeSSH.m index 8ff9bd1..60538e9 100644 --- a/matlab/FindFreeSSH.m +++ b/matlab/FindFreeSSH.m @@ -11,7 +11,7 @@ function host = FindFreeSSH(host_list, wait_time, command) % default: 600 seconds % % 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 % @@ -28,17 +28,38 @@ if (nargin<2) wait_time = 600; end +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) host = host_list{n}; [status, result] = unix(['ssh ' host ' ' command]); - - if isempty(result) + + if (isempty(result) && status==1) disp(['FindFreeSSH:: found a free host: ' host ]); return - else + elseif (~isempty(result) && status==0) disp(['FindFreeSSH:: ' host ' is busy running openEMS ... ' ]); + else + disp(['FindFreeSSH:: shh connection to ' host ' failed ... ' ]); end end