perf trace -F maj
http://man7.org/linux/man-pages/man1/perf-trace.1.html
Para conectarse a un proceso existente, use
-p $PID
. Si no desea mostrar las llamadas del sistema, pase--no-syscalls
también. Los argumentos de la llamada al sistema no se mostrarán con el mismo nivel de detalle questrace
.
Трубопроводы find... 2>&1
- tee -a "$sentPurgeLogFile"
. Это добавит вывод команды find
в файл, заданный значением $sentPurgeLogFile
, но также отправит тот же вывод в стандартный вывод цикла while
.
Перенаправление вывода цикла while
в «главный» файл журнала:
while...; do
# find commands here, e.g.
find "$sentPurgerFolder" -mtime +7 -print -delete 2>&1 | tee -a "$sentPurgeLogFile"
done >master.log
Таким образом, вы сохраните выходные данные для каждого отдельного клиента в своем собственном файле журнала, но также сохраните все выходные данные в master.log
.
Неясно, выполняет ли цикл while
один цикл find
или несколько циклов. Если он выполняет один find
, удалите параметр -a
для tee
, чтобы создавать новый файл журнала для этого клиента каждый раз при выполнении этой команды. Если вы запускаете несколько команд find
, вы можете сделать это только для первой tee
. Это если вы не хотите хранить накопленные журналы по всем вызовам скрипта, очевидно (, и в этом случае вы также можете использовать >>master.log
после цикла вместо>master.log
).
Я нашел другой метод, который полностью опровергает этот пост, но я попытаюсь проиллюстрировать, что я сделал....
Итак, у меня есть файл конфигурации клиента, разделенный символом '%'. Это считывается построчно процессом sftp, который будет отправлять и получать данные от клиентов. Это выглядит примерно так:
...
client_1%FileContent_1%xml%...(client connection info)
client_1%FileContent_2%txt%...(client connection info)
client_1%FileContent_3%pdf%...(client connection info)
client_2%FileContent_1%xml%...(client connection info)
client_2%FileContent_2%pdf%...(client connection info)
...
Итак, мой процесс очистки читает это и просматривает первые три поля. Они используются для составления базового -пути для каждого клиента.
/xmit/client/outbound
Теперь в каждой из вышеуказанных папок есть папки «отправлено» или «получено» и «журнал».
/xmit/client/outbound/sent
/xmit/client/outbound/log
И этот процесс sftp отправляет и получает файлы для этих клиентов, и когда каждый файл обрабатывается, он помещает указанный файл в папки /sent и /received, а полная трассировка отправки/получения указанного файла заносится в /log. папки.
Итак, процесс очистки, который я пишу, считывает тот же файл конфигурации, чтобы найти папки для очистки, но я хочу консолидировать файлы журналов очистки для каждого клиента.
#
# Inits....
#
basepath=/xmit
workingdir=$basepath/bin/Purge
purgeProcessLogFile=$workingdir/outboundPurge.log
#
cnfgFl=/xmit/bin/OutBoundScripts/clientsftpconfigoutbound.txt
# Config File Ref
#
declare -i cnfgFlNbrOfLns=`wc -l "$cnfgFl" | cut -d ' ' -f 1`
# Count lines in config file...
#
# Set beginning line and work from beginning line to ending line...
#
firstpass=1
declare -i cnfgFlStrtLn="53"
declare -i currentLnNbr=$cnfgFlStrtLn
lastClient='0'
#
# Begin while loop...
#
while [ "$currentLnNbr" -le "$cnfgFlNbrOfLns" ]
do
#
# Set what line to read from and read the data in...
#
option="$currentLnNbr"p
cnfgFlLn=`sed -n $option $cnfgFl`
#
# Increment counter for the next loop, you've allredy got the data...
#
declare -i currentLnNbr=`expr $currentLnNbr + 1`
#
# Check if very first character in config line is not a "#" and proceed.
#
fld=`echo $cnfgFlLn | cut -c1-1`
#
if [ "$fld" != \# ]
then
#
# Get file content... (ex: '7501' )
#
cntnt=`echo $cnfgFlLn | cut -d "%" -f 2`
#
# Extract account from
#
currClient=`echo $cnfgFlLn | cut -d "%" -f 1`
#
if [ $currClient != \# ]
then
#
# Check if on new account. If new account, set 'lastClient' to current account
# and reset log files...
#
if [ "$lastClient" != "$currClient" ]
then
#
lastClient=$currClient
#
# Set current date and time stamp...
#
dt=`date +%Y%m%d``date +%H%M%S`
#
# Set sent purge log...
#
sentPurgeFolder=$basepath/$currClient/outbound/sent
sentPurgeLogFile=$sentPurgeFolder/SentPurgeLogFile\_$dt.log
#
# Set sent log purge log...
#
sentLogPurgeFolder=$basepath/$currClient/outbound/logs
sentLogPurgeLogFile=$sentLogPurgeFolder/SentLogPurgeLogFile\_$dt.log
#
# Prime new logfiles...
#
cat /dev/null > $sentPurgeLogFile
cat /dev/null > $sentLogPurgeLogFile
fi
#
# See if there are any files to purge...
#
declare -i cntntFilesToPurge=`find $sentPurgeFolder -mtime +7 -print | wc -l`
if [ "$cntntFilesToPurge" -gt "0" ]
then
#
# 'cd' to sent folder, purge and upate logfile...
#
cd $sentPurgeFolder
dt1=`date +%Y%m%d``date +%H%M%S`
echo $dt1 - Purging "$cntntFilesToPurge" "'"$cntnt"'" data files that are 7 days or older from $sentPurgeFolder >> $purgeProcessLogFile
find $sentPurgeFolder -mtime +7 -print -delete >> $sentPurgeLogFile 2>&1
else
dt1=`date +%Y%m%d``date +%H%M%S`
echo $dt1" - No ""'"$cntnt"'" data files that are 7 days or older to purge from $sentPurgeFolder >> $purgeProcessLogFile
fi
#
# See if there are any logs to purge...
#
declare -i logFilesToPurge=`find $sentLogPurgeFolder -mtime +7 -print | wc -l`
if [ "$logFilesToPurge" -gt "0" ]
then
#
# 'cd' to logs folder, purge and upate logfile...
#
cd $sentLogPurgeFolder
dt1=`date +%Y%m%d``date +%H%M%S`
echo $dt1 - Purging "'"$cntnt"'" 'purge log' data are 7 days or older from $sentPurgeFolder >> $purgeProcessLogFile
find $sentLogPurgeFolder -mtime +1 -print -delete >> $sentLogPurgeLogFile 2>&1
else
dt1=`date +%Y%m%d``date +%H%M%S`
echo $dt1" - No logfiles for ""'"$cntnt"'" data that are 7 days or older to purge from $sentPurgeFolder >> $purgeProcessLogFile
fi
fi
fi
done
#
# E N D O F F I L E
#
Секция:
declare -i cntntFilesToPurge=`find $sentPurgeFolder -mtime +7 -print | wc -l`
if [ "$cntntFilesToPurge" -gt "0" ]
then
cd $sentPurgeFolder
dt1=`date +%Y%m%d``date +%H%M%S`
echo $dt1 - Purging "$cntntFilesToPurge" "'"$cntnt"'" data files that are 7 days or older from $sentPurgeFolder >> $purgeProcessLogFile
find $sentPurgeFolder -mtime +7 -print -delete >> $sentPurgeLogFile 2>&1
else
dt1=`date +%Y%m%d``date +%H%M%S`
echo $dt1" - No ""'"$cntnt"'" data files that are 7 days or older to purge from $sentPurgeFolder >> $purgeProcessLogFile
fi
#
# 'cd' to logs folder, purge and upate logfile...
#
declare -i logFilesToPurge=`find $sentLogPurgeFolder -mtime +7 -print | wc -l`
if [ "$logFilesToPurge" -gt "0" ]
then
cd $sentLogPurgeFolder
dt1=`date +%Y%m%d``date +%H%M%S`
echo $dt1 - Purging "'"$cntnt"'" 'purge log' data are 7 days or older from $sentPurgeFolder >> $purgeProcessLogFile
find $sentLogPurgeFolder -mtime +1 -print -delete >> $sentLogPurgeLogFile 2>&1
else
dt1=`date +%Y%m%d``date +%H%M%S`
echo $dt1" - No logfiles for ""'"$cntnt"'" data that are 7 days or older to purge from $sentPurgeFolder >> $purgeProcessLogFile
fi
Было раньше:
#
# 'cd' to sent folder, purge and upate logfile...
#
cd $sentPurgeFolder
dt1=`date +%Y%m%d``date +%H%M%S`
find $sentPurgeFolder -mtime +7 -print -delete >> $sentPurgeLogFile 2>&1
#
# 'cd' to logs folder, purge and upate logfile...
#
cd $sentLogPurgeFolder
dt1=`date +%Y%m%d``date +%H%M%S`
find $sentLogPurgeFolder -mtime +1 -print -delete >> $sentLogPurgeLogFile 2>&1
Это удовлетворило мои потребности в журнале «очистки».
Хорошо, я кусаю. Учитывая то, что я думаю, вы пытаетесь достичь. Вот что я мог бы попытаться использовать.
Моё предположение:
#!/bin/sh -
masterlog="/some/place/some.file"
dirlist="
/one/place
/two/place
/three/place
"
for d in $dirlist
do
cd $d
for f in `find. -mtime +7 -maxdepth 1 -type f`
do
cat $f >>$masterlog
echo ''>$f
done
done
exit
НЕ ПРОВЕРЕНО
Я полагал, что вы пытаетесь собрать содержимое всех отдельных журналов в $masterlog
, а затем очистить содержимое этих отдельных журналов.
Если я был прав. Тогда это будет сделано.:)
ХТХ