0

I'm writing log-parsing automation script. Log directory structure is /var/log/yyyy/mm/dd/mainlog.ec Variables for this path are not constant, for sure they are like a=date +%d b= $[$a-7] This script will run in cron once per week and calculate some data from logs(for past 7 days), generate a report and send it on my e-mail. So i need to use a range of dates in path to logs i faced a some troubles creating some parsing-log script.

    #!/bin/bash
    a=`date +%d`
    b=$[$a-7]
for i in pc1 pc2 pc3; do echo "$i `cat /var/log/2015/02/{$a..$b}/mainlog-1.ec | grep $i | wc -l`"; done

but i recieve:

cat: /var/log/2015/02/{10..18}/mainlog-1.ec: No such file or directory
pc1 
cat: /var/log/2015/02/{10..18}/mainlog-1.ec: No such file or directory
pc2
cat: /var/log/2015/02/{10..18}/mainlog-1.ec: No such file or directory
pc3 

How can i get {a..b} regexp in path working with my variables?

  • You cannot use variables in the brace expansion, since it happens *before* variables are substituted. Instead, you can use `seq`. But try to explain what is your general problem, since there can be better ways to handle it. – fedorqui Feb 20 '15 at 14:03
  • Look, i'm writing log-parsing automation script. Log directory structure is /var/log/yyyy/mm/dd/mainlog.ec Variables for this path are not constant, for sure they are like a=`date +%d` b= $[$a-7] This script will run in cron once per week and calculate some data from logs(for past 7 days), generate a report and send it on my e-mail. So i need to use a range of dates in path to logs – Viserion Targaryen Feb 20 '15 at 14:10
  • 1
    Ahh, i found the solution here. I just need to use eval before cat and all works fine for me for i in pc1 pc2 pc3; do echo "$i `eval "cat /var/log/2015/02/{$a..$b}/mainlog-1.ec | grep $i | wc -l"`"; done – Viserion Targaryen Feb 20 '15 at 14:25

0 Answers0