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
MainDir=/path/to/dir/containing/subdirs
# cd into dir
cd $MainDir
for dir in $(ls); do
#fetch start time of uut
grep -i "01_node_setup" $dir/his_file | tail -1 >> /home/xtee/sst-logs.out
#check if sysconfig.out exists
if [ -f $dir/sysconfig.out];
then
    grep -A 1 "Drive Model" $dir/sysconfig.out | tail -1 >> /home/xtee/sst-logs.out
else
    grep -m 1 "Pair0 DIMM0" $dir/node0/trans_file_prev/*setupsys* | tail -1 >> /home/xtee/sst-logs.out
fi 
done
#cd back to where we started
cd $OLDPWD
 Basically I want to run thisA nice guy helped me with the script to execute on all, and the existing sub directoriesscript above is what came out. It worked alright however, the sst-logs.out file displays binary file /some/subdirectory/ instead of a certain directorythe output of the grep. What do I dois wrong in the script? Thanks!