Skip to main content
1 of 2
JudeJitsu
  • 131
  • 1
  • 5

Shell Script to Execute Shell Script to All Subdirectories

I am making a script to simplify my daily tasks. Everyday, I have to grep for a few things inside a company server. It was okay, however, now, they have segregated each object into sub directories. I am looking for a solution in which my existing shell script will execute repeatedly into each sub directory inside a certain directory. How do I do this? I am quite new to Linux and still learning the ropes.

Here's my script:

#!/bin/bash

#fetch start time of uut
grep -i "01_node_setup" his_file | tail -1 >> /home/xtee/sst-logs.out

#check if sysconfig.out exists
if [ -f sysconfig.out];
then
    grep -A 1 "Drive Model" sysconfig.out | tail -1 >> /home/xtee/sst-logs.out
else
    grep -m 1 "Pair0 DIMM0" node0/trans_file_prev/*setupsys* | tail -1 >> /home/xtee/sst-logs.out
fi

Basically I want to run this script to execute on all the existing sub directories of a certain directory. What do I do? Thanks!

JudeJitsu
  • 131
  • 1
  • 5