I am running matlab on 48 virtual machines and would like to automate it. I ssh into the machines then use matlab -r matlab_command > outfile.txt &
to get t
I am using this workaround, which provides a dummy standard in:
matlab -r matlab_command > outfile.txt < /dev/null &
Use nohup command on UNIX to prevent MATLAB stop when you logout.
nohup matlab -nodisplay -nosplash -r matlab_command > outfile.txt &
And don't forget to include exit;
at the end of matlab_command script.
UPDATE:
Try this solution: Is it possible to run MATLAB in the background under UNIX?
There is an explanation here.
If you are using file:
nohup matlab -nodesktop -nodisplay < file.m > result.txt &
You might need to press enter after you execute this.
The real clean solution to your problem is to use GNU Screen. Then you will not loose your Matlab session and you can always get back into the Matlab prompt. Very helpful if somebody went wrong with your Matlab code and you need to debug a little.
Just fire up 'screen
' (after you have the package installed, included in all major distributions). You will have a typical prompt, but inside a persistent, virtual terminal. Start your matlab as usual, omit any backgrounding. Then press CTRL+A, D (first CTRL+A, then d). You will be out of screen. You can logout. If you want to get back to your screen session, run screen -r
. If you want, you can also directly start screen matlab [...]
in the first place. It will have the effect that your virtual session is also dropped when matlab quits.
I had trouble with screen: matlab started but had no notion of what had been passed through stdin. It simply ignored it.
But I succeeded with tmux. Here is the command line I used,
local$ ssh -f me@remote 'tmux new-session -d -s matlab "matlab -nojvm -nodesktop -nodisplay -nosplash </path/to/myscript.m"'
You can then ssh into the remote host (indicated here by the prefix remote$
) and check things by issuing remote$ tmux a -t matlab
. You detach out to your remote host by pressing Ctrl-b d
. You list sessions with remote$ tmux ls
(like screen). You kill the session from inside with Ctrl-b &
and from outside with $remote tmux kill-session -t matlab
.
But I discovered that you can also attach to your tmux session from your local host directly:
local$ ssh -t me@remote 'tmux a -t matlab'
Notice I had to use -t
here in place of -f
.
I found some useful link Tips for Running Large Computations and nohup
nohup nice matlab -nodisplay -nosplash <matlab_command.m > outfile.txt > 2>dev/null &
maybe this can fix your problem.