ill be the first to admit i am a bit of a bash scripting noob... but ive come againest a small problem...
LOG=/var/log/local2.log
for i in SEC-0 SEC-1 SEC-2 SEC-3 SEC-4 SEC-5 SEC-6 SEC-7
do
grep $i $LOG | wc -l
done
The above works and gives me 8 different values. Later on in the script I wish to echo these strings, so i would like them as varibles.
Is there anyway to assign each total against a varible so when this is finished I have... something like..
$SEC-0=some number
$SEC-1=some number ..... etc etc
I hope I have made this clear, thanks in advanced....
Not really, but you can either use a more parowerful scripting language and use arrays, or create a variable containing your 'SEC-?' entries.
#!/bin/sh
LOG=/var/log/local2.log
SEC="SEC-0 SEC-1 SEC-2 SEC-3 SEC-4 SEC-5 SEC-6 SEC-7"
for i in $SEC
do
grep $i $LOG | wc -l
done
echo "$SEC" | awk '{ print $3 }' # prints "SEC-2" (the third 'SEC' string)
grep `echo "$SEC" | awk '{ print $5 }'` $LOG | wc -l #searches the log for "SEC-6"
Does that help?
Ive now found what I was looking for ...
LOG="/var/log/local
level=(Emergency Alert Critical Error Warning Notification Informational Debugging)
for i in 0 1 2 3 4 5 6 7
do
printf "${level[$i]} - " ; grep -c SEC-$i $LOG
done
But the only thing im unsure of is how to allow for the wildcard in for the $LOG variable ????
edit by bakunin: please use "code"-tags when you post program code. Thx.
If you don't use quotes the wildcards should be evaluated.
LOG=/var/log/local?.log
it doesnt seem to like that it says ..
./sysloghtml.sh: line 14: [: /var/log/local2.log: binary operator expected
Unable to find logfile at /var/log/local?.log
What is in line 14 of your script?
If you are testing against a wildcard, you will get an error if it expands to more than one filename.