3

I wrote a bash script and i got these message:

/home/myname/documents/myscripts/run_tearingmode.sh: line 44: mpirun2: command not found:

Here the relevant part of the script

if [[ "$run_jobs" == "y" ]]
 then
 printf "The jobs run one after the other. Have fun with the analysis. \n "
 for ((i=1;i<=$number_subfolders;i++))
  do
  sub_folder=${main_folder}_$i
  cd
  cd gkw/run/${main_folder}/$sub_folder #change into certain subfold
  pwd
  mpirun2 -np 8 ./gkw_btppx-gnu-DP_3481.x  #run on all 8 frames #line 44 Here is the problem 
  cd
 done
fi

My problem is, that when i type in the line as just a command in the certain folder, the programm runs correctly. This shows to me that i implemented it correctly. With pwd i also know that i am in the right folder. I didn't found out where i made the mistake. Do i need a certain bracket or equivalent things in a script for running a program? I also deleted the blank in front of the command, but nothing changed. What is wrong/missing?

EDIT: The problem was, that you can't run an alias from bashrc in such a script. So i added:

mpirun2='/Path/to/mpirun'

to my script and changed the command in the script to:

"$mpirun2" -np 8 ./gkw_btppx-gnu-DP_3481.x  #run on all 8 frames

This works. Thanks a lot. (I unfortunately can't write this answer myself as a starter :) )

user2867054
  • 59
  • 1
  • 7
  • 1
    Check the value of the `PATH` environment variable when your script is run (i.e. `echo $PATH`). Specifying the full path to `mpirun2` should help. – Stefan Näwe Oct 10 '13 at 13:39

2 Answers2

1

I think if you add a shebang on top of your script

#/usr/bin/env bash

and the full path to your executable (this command shows it which mpirun2) this should work.

zzeroo
  • 5,466
  • 4
  • 33
  • 49
  • I do have #!/bin/bash at the beginning of my script. Until i want to start the programm, my script runs well. I also have named the mpirun2 as an alias in the bashcr alias mpirun2='/home/myname/mpich2/bin/mpirun' .What is the acutal path of that folder? – user2867054 Oct 10 '13 at 13:35
  • 4
    Your alias is not available in your script. Instead of an alias, add this to your `.profile` or `.bash_profile` (not `.bashrc`): `PATH="/home/myname/mpich2/bin/mpirun:$PATH"`. – chepner Oct 10 '13 at 13:42
1

If mpirun2 is not on the user's PATH ('which -a' will return nothing). You must invoke it using full path to it:

/full/path/to/mpirun2 -np 8 ./gkw_btppx-gnu-DP_3481.x
LMC
  • 10,453
  • 2
  • 27
  • 52