質問

I'm currently monitoring a number of dirs for log files; specifically those just created. It's been a long time since my Linux and after some trial and error I've hacked together what I need but it takes a full 20secs or more to return. I'm hoping I can have an expert look at it and advise me on something a little more streamlined.

find . -type f -follow -print | xargs ls -ltr 2>/dev/null | grep '2\?10' | tail

So for example find the last 10 files matching the name. Optimally I'd like to turn this into a bash script that accepts one argument and replaces the grep expression but I figure one thing at a time.

Thanks for your help in advance!

正しい解決策はありません

他のヒント

I bit the bullet and wrote the script; I'll tinker with it more later.

#!/bin/bash

if [ $# != 2 ]; then
  echo findLog Usage: findLog [3 digit cluster] [pick 1: main message service detail soap]
  exit 0
fi

if [ "$2" == "service" ]; then
     file="$2-time-"
elif [ "$2" == "detail" ]; then
     file="$2-time-"
else file="$2-"
fi

cluster="$1"

#store logpaths for readability
a="/pathto/A"
b="/pathto/B"
c="/pathto/C"
d="/pathto/D"
e="/pathto/E"
f="/pathto/F"
g="/pathto/G"
h="/pathto/H"


logpaths=( $a $b $c $d $e $f $g $h )

for i in "${logpaths[@]}"
do
   ls -ltr "$i"/*.log | grep "$file"${cluster:0:1}${i: -1}${cluster: -2}
done
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top