oracledba.help

BASH Script findIt.sh

<- Scripts

 #!/bin/bash
 # Purpose: Find files on system that contain a specific string.
 # Note:    / is always searched.

 # User Vars
 FIND_STR="ORACLE_SID";
 FILE_SPEC=".ora";
 INC_DIRS="home u01 u02";                # Space Delimited
 EXC_DIRS="boot,dev,media,mnt,proc,sys"; # Comma Delimited

 # Heading
 clear
 printf "FIND_STR:  $FIND_STR\n";
 printf "FILE_SPEC: $FILE_SPEC\n";
 printf "INC_DIRS:  $INC_DIRS\n";
 printf "EXC_DIRS:  $EXC_DIRS\n\n";
 printf "Process Running...\n\n"

 # Process
 grep --include=\*$FILE_SPEC -rnw / --exclude-dir= -e "$FIND_STR" > /tmp/findIt.$FIND_STR.txt
 for d in ${INC_DIRS[@]}
 do
    printf "Processing: $d \n"
    grep --include=\*$FILE_SPEC -rnw /$d --exclude-dir= -e "$FIND_STR" >> /tmp/findIt.$FIND_STR.txt
 done

 # End
 printf "\n*** Process Ended *** \n\n"
 printf "Results file:\n"
 ls -l /tmp/findIt.$FIND_STR.txt