3

I have a very simple question.

I've created multiple scheduled bash files that run 3 or 4 MATLAB scripts. Something like:

cat /pathtobash/bash_script.sh
#!/bin/bash

~/path/run_mat_script.sh ~/path2/matlab matlab_script 
~/path/run_mat_script.sh ~/path3/matlab matlab_script2
~/path/run_mat_script.sh ~/path2/matlab matlab_script3

One of those MATLAB scripts in one (or multiple) bash scripts, is not running as it should and just "hangs"

How can I find out which one is failing?

I've tried both "top" and "ps" commands, which just tell me that a MATLAB command is running.

For example:

ps ax | grep MATLAB
  498 ?        Sl    45:00 /opt/matlab/bin/glnxa64/MATLAB -nodisplay -nosplash
 2059 ?        Sl    32:35 /opt/matlab/bin/glnxa64/MATLAB -nodisplay -nosplash
 4098 ?        Sl    14:33 /opt/matlab/bin/glnxa64/MATLAB -nodisplay -nosplash
 5690 pts/9    S+     0:00 grep MATLAB
29409 ?        Sl    70:20 /opt/matlab/bin/glnxa64/MATLAB -nodisplay -nosplash
29797 ?        Sl    69:10 /opt/matlab/bin/glnxa64/MATLAB -nodisplay -nosplash
32233 ?        Sl    50:00 /opt/matlab/bin/glnxa64/MATLAB -nodisplay -nosplash

Thank you for the help

Elcook
  • 165
  • 2
  • 10

2 Answers2

1

I would try printing the last PID after each call in bash, then you can match each of your running scripts to a unique identification number.

Check this example: https://stackoverflow.com/a/18123333/6404262

Community
  • 1
  • 1
yumilceh
  • 11
  • 1
1

I would do something like this.

./proc1 &
proc_1=$!
./proc2 &
proc_2=$!

#Wait for processes to finish        
if `echo wait $proc_1 $proc_2`; then
    echo success
else
    echo "A proc failed, either: $proc_1 $proc_2"
fi

#Check exit status

echo $?

And you can of course print your pids using echo "Pid:$proc_2" when creating them.

Ola
  • 91
  • 1
  • 2
  • 8