bash - Need help achieve a file viewing script -
i need make bash script file viewing.
i have files 30 minute, automatic ranges in folders named date ex:
/data/ operator/20160515/exploit/ /data/ operator/20160516/exploit/ /data/ operator/20160517/exploit/ /data/operator/20160518/prod/ /data/operator/20160518/prod/ /data/operator/20160518/prod/
each folder contains files of day in format "datehour-toto.tz" in script type eg "send.sh 201605151530 201605171300" automatically list files between these 2 dates in ls example ?
i not know start because made me tough air achieve? because takes every file checker in 2 dates , times
i found might start, not know how tell exploit subdirectory
directory="data/" find ${directory} -type f | awk -vstart=$1 -vstop=$2 ' { t = substr($0, length("'${directory}'")+10, 12) } t > start && t < stop { print }' ./send.sh 201508190810 201508190900 data/20150819/201508190821-toto.tz data/20150819/201508190823-toto.tz data/20150819/201508190820-toto.tz data/20150819/201508190822-toto.tz
if me , not speak english .
here faster way:
find data -maxdepth 2 -type d -name exploit | awk -v start=$1 -v end=$3 -f/ '$2>=start && $2<=end' | xargs -i{} find "{}" -type f | awk -v start=$1$2 -v end=$3$4 -f/ '$4>=start && $4<=end'
usage:
./send.sh 20160515 1530 20160517 1300
there fast , easy way on command line instead of in script:
find data/2016051*/exploit -type f | awk -f/ '$4>=201605151530 && $4<=201605171300'
how work?
find data/2016051*/exploit
finds directories named exploit inside of directories named 2016051*, so: 20160510 - 20160519. saves time not considering other ones. way faster:
find data/2016051[567]/exploit
it finds inside of directories 20160515, 20160516, 20160517.
if wanted search 20160529 - 20160601, try:
find data/20160*/exploit
or, faster:
find data/20160[56]*/exploit
Comments
Post a Comment