Sample Header Ad - 728x90

how to "execute command on file in multiple subdirectories within containing folder" i.e cd into each subdirectory containing file and execute command

0 votes
1 answer
101 views
I have a file named filename.sh in different directories. I am trying to simultaneously submit this file to run on a number of cluster nodes. I need to find this file wherever they may be, cd into their containing folder and execute the command "sbatch run_code.sh" This is what I have tried. find . -mindepth 1 -type f -name filename.sh -exec sbatch run_code.sh {} \; And it works except it runs command from current folder which does not contain dependencies needed to run the code. alternatively I am leaning towards a for loop like this
for d in dirname; do 
  cd "$(dirname "$(find . -type f -name filename.sh)")" && sbatch run_code.sh)
done
which does not work. I look forward to getting some help here. Please.
Asked by Daniel Ajuzie (3 rep)
Mar 30, 2022, 04:33 PM
Last activity: Mar 30, 2022, 07:08 PM