0

I am trying to read all the log files in a directory and output the content (appending the file name in front of each line) into a master log file. I am getting this error while the script runs:

echo: write error : Disk quota exceeded

below is my code

MasterLog=/home/did/masterfile.log

for file in /home/logs/*.log
do
      while read line;
      do
         echo ${file%%.*} ${line} >> $MasterLog
      done<${file}
done
echo "done"
Didier
  • 51
  • 7
  • That's odd. The error you *should* be getting is "MasterLog: command not found" "$MasterLog: ambiguous redirect". Can you please double check that this is an exact copy of the script you're running? – that other guy Mar 20 '20 at 22:59
  • I edited it. removed spaced around equal sign. – Didier Mar 20 '20 at 23:14
  • 2
    It looks quite clear: you are over quote. Remove files. – Poshi Mar 20 '20 at 23:22
  • 1
    Does this answer your question? [Disk quota exceeded warning in server](https://stackoverflow.com/questions/23194890/disk-quota-exceeded-warning-in-server) – Digvijay S Mar 21 '20 at 00:06
  • 2
    Once you increase your disk quota, you really need to find a more efficient way to prefix every line in a file. Either sed or awk would be orders of magnitude faster. – rici Mar 21 '20 at 02:09
  • BTW, not only would sed or awk be faster, they would also be less buggy. Always quote your expansions; see [I just assigned a variable, but echo $variable shows something else](https://stackoverflow.com/questions/29378566/i-just-assigned-a-variable-but-echo-variable-shows-something-else) describing the issue at hand. – Charles Duffy Mar 21 '20 at 03:37
  • Also, `read` itself will subtly corrupt your data when not given the `-r` argument. See [BashFAQ #1](https://mywiki.wooledge.org/BashFAQ/001) for guidance regarding its correct use. – Charles Duffy Mar 21 '20 at 03:40
  • http://shellcheck.net is a resource worth using before asking questions here; it automatically identifies both the issues I mentioned above. – Charles Duffy Mar 21 '20 at 03:43

0 Answers0