S
S
ss44v2018-05-18 22:14:06
bash
ss44v, 2018-05-18 22:14:06

Error in bash script, what's wrong?

#!/bin/bash
mask="/var/log/WARNING*"
logfile="tmp/error.log"
rm $logfile

for file in $(ls -l $mask)
do
 while read line
 do
  echo $line >> $logfile
 done < $file
 echo $line >> $logfile
done

grep -E -h -s "/[a-z]{2,}/\S+" $logfile

exit 1

Errors appear:
rm: cannot remove 'tmp/error.log': No such file or directory
ls: cannot access '/var/log/WARNING*': No such file or directory
but the files are there

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jcmvbkbc, 2018-05-19
@jcmvbkbc

rm: cannot remove 'tmp/error.log': No such file or directory

for file in $(ls -l $mask)
do
 while read line
 do
  echo $line >> $logfile
 done < $file
 echo $line >> $logfile
done

Sorry, but why move files line by line when you can do this:
find -name "$mask" -type f -print0 | xargs -0 cat >> $logfile

R
RidgeA, 2018-05-18
@RidgeA

maybe
?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question