The script not working as expected files dump path
- by user3319390
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