The script not working as expected files dump path
Posted
by
user3319390
on Server Fault
See other posts from Server Fault
or by user3319390
Published on 2014-06-11T06:53:48Z
Indexed on
2014/06/11
9:27 UTC
Read the original article
Hit count: 202
I have a script needs to be dump matching cname from my file contains and then matching scode to dump file to $cname/$year/$month/$day/
into files like access and error logs
#!/bin/sh
#base_dir="/home/vizion/Desktop"
path="/home/vizion/Desktop/adn_DF9D_20140515_0005.log"
name=$(basename "$path" ".log")
for x in *.log; do year=${x:9:4}; month=${x:13:2}; day=${x:15:2}; done
while read -r line
do
cname=$(echo ${line} | awk '{split($7,c,"/"); print c[3]}')
scode=$(echo ${line} | awk -F"[ ]" '{print $9}')
[[ ! -d "$cname/$year/$month/$day" ]] && mkdir -p "$cname/$year/$month/$day/"
[[ ( ${scode} -ge 200 ) && ( ${scode} -le 399 ) ]] && {
# [[ ! -d "$cname/$year/$month/$day" ]] && mkdir -p "$cname/$year/$month/$day/"
echo ${line} >> /home/vizion/Desktop/$cname/$year/$month/$day/${cname}_${name}_access.log
}
[[ ( ${scode} -ge 400 ) && ( ${scode} -le 599 ) ]] && {
[[ ! -d "$cname/$year/$month/$day" ]] && mkdir -p "$cname/$year/$month/$day"
echo ${line} >> ${cname}_${name}_error.log
}
done < $path
i am able to filter logs but not not dumping the exact location
It's going other locations
suggest to me correction in script
© Server Fault or respective owner