Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
2 Edited the script to the working one from a nice guy.
source | link

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!

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!

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

A nice guy helped me with the script, and the script above is what came out. It worked alright however, the sst-logs.out file displays binary file /some/subdirectory/ instead of the output of the grep. What is wrong in the script?

1
source | link

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!