I am writing a script to read multiple log files and find lines with a specific string. However I am getting an error when trying to egrep/grep on the file.
I have a file that has the names of the log files to read (see below)
files.txt
./code_a.log
./code_b.log
log_analysis.ksh
#!/bin/ksh
platform=$1
lw_platform=$(echo "$platform" | tr '[:upper:]' '[:lower:]')
log_dir="/project/$lw_platform/logs/"
read_file="/user/LogAnalysis/files.txt"
out_file="/user/LogAnalysis/out3.txt"
echo $lw_platform
echo $log_dir
while -r line; do
echo "Began: $line" >> $out_file
cd ${log_dir}
echo $(pwd)
egrep -n 'ERROR:' $line >> $out_file
echo "End: $line" >> $out_file
done < $read_file
CONSOLE OUTPUT
test
/project/test/logs/
/project/test/logs
.grep: 0652-033 Cannot open ./code_a.log
However I don't get this error if I run the same egrep
command directly into the shell. Proves that I have the permissions to read the file.
code_a.log
andcode_b.log
are available in the script's current directory. If that is not the case, then either update the text file with the full absolute path of the files, orcd
in the scirpt to the correct directory before reading from the file.cd
in the script actually succeed? What is the full output of the script when you encounter the error?cd
succeeds (I didpwd
to check).out_file
.