Run multiple matlab instances in nohup bash script

I am trying to do something like the following. Right now I am connecting via ssh to a remote computer and starting my analysis with the nohup command as

nohup matlab -nodesktop -nodisplay < mycode.m > output.txt 2>&1 & 

Now I want to write a script that runs in the background with several nohup commands one after another. I managed to do

 #!/bin/bash matlab -nodesktop -nodisplay -r "mycode;quit;" > output.txt 

But not only does the code work with only one processor, but also in an infinite loop and never ends.

Can i solve this? It is important that I can close the terminal after running script.sh

EDIT: Thanks to you, I can do and let the next thing work well.

 ssh user@ipaddress screen cd folder1/ nohup matlab -nodesktop -nodisplay < mycode.m > output.txt 2>&1 & exit screen cd folder2/ nohup matlab -nodesktop -nodisplay < mycode.m > output.txt 2>&1 & exit 

Can I make a script now? Since I noticed that at any time when I type screen , I have to press Enter immediately after.

EDIT2: @Peter I did what you suggested

 #!/bin/bash cd folder1/ matlab -nodesktop -nodisplay -r "mycode;quit;" < /dev/null > output.txt cd folder2/ matlab -nodesktop -nodisplay -r "mycode;quit;" < /dev/null > output.txt 

But only the first matlab works, how is this possible?

+4
source share
2 answers

Having compiled all the suggestions and ideas, you can try:

 #!/bin/bash ssh user@ipaddress " cd folder1/ nohup matlab -nodesktop -nodisplay < mycode.m > output.txt 2>&1 & cd folder2/ nohup matlab -nodesktop -nodisplay < mycode.m > output.txt 2>&1 & " 

or

 #!/bin/bash ssh user@ipaddress " cd folder1/ nohup matlab -nodesktop -nodisplay -r 'mycode;quit;' < /dev/null > output.txt 2>&1 & cd folder2/ nohup matlab -nodesktop -nodisplay -r 'mycode;quit;' < /dev/null > output.txt 2>&1 & " 

or

 #!/bin/bash ssh user@ipaddress " cd folder1/ screen -dm matlab -nodesktop -nodisplay < mycode.m > output.txt 2>&1 cd folder2/ screen -dm matlab -nodesktop -nodisplay < mycode.m > output.txt 2>&1 " 

or

 #!/bin/bash ssh user@ipaddress " cd folder1/ screen -dm matlab -nodesktop -nodisplay -r 'mycode;quit;' < /dev/null > output.txt 2>&1 cd folder2/ screen -dm matlab -nodesktop -nodisplay -r 'mycode;quit;' < /dev/null > output.txt 2>&1 " 

You can also try expect to control matlab instead of sending mycode.m or using -r for it.

Try making nohup on screen . And I think you no longer need to add & to it, since screen works as the default daemon already.

+4
source

Thank you all for your help. I think I found what I was looking for.

  • i ssh into my car
  • create a new screen using the screen -dmS analysis
  • run the script (see below) nohup ./script.sh &
  • close exit screen
  • check work with top (as usual :))

This is my script.sh

 #!/bin/bash matlab -nodesktop -nodisplay -r "cd folder1/; run('mycode.m'); quit" < /dev/null > output.txt matlab -nodesktop -nodisplay -r "cd folder2/; run('mycode.m'); quit" < /dev/null > output.txt 

Analyzes run one after another! Fine!

+1
source

Source: https://habr.com/ru/post/1499607/


All Articles