随笔-常用命令-零散
【A1】某一时间点开始执行某一命令
view
xdate="$(date +%F) 16:05:00";sleep $(( $(date -d "$xdate" +%s) - $(date +%s) )) && echo "666"
【A2】日志分析 对于有日志分割 使用 tail -F
view
tail命令 对于有进行日志分割的使用-F替代-f,详细说明见 tail --help
【A3】日志分析
view
统计请求时间分布: egrep --no-filename '^2023-10-09 17:2[3-4].*_WsServerCallBack.*Sending message' $(ls -rt cs*log | tail -n 500) -A 3 | grep forwardMsg -B 2 | egrep '^2023' | cut -c12-19 | awk '{x[$1]++;} END{for(i in x) print(i ":" x[i])}' | sort
> echo "2023-10-09 17:24:07.857568" | cut -c12-19 => 17:24:07
【A4】日志分析
view
# 使用 bash mlog-save.sh "2023-10-10 09:00:00"
[ "$1" != "" ] && {
dir_name="mlog_${1}"
dir_name=${dir_name/ /-}
mkdir $dir_name
echo "FILTER LOGS..."
log_start=$(egrep -l "^$1" $(ls -rt cs*log | tail -n 500) | head -n 1)
[ "$log_start" != "" ] && {
echo "FILTER LOGS SUCCESS, SAVE LOG"
cp -a $(ls -rt cs*log | egrep -w "^${log_start}$" -A 500) $dir_name/
cd $dir_name || exit
log_list=$(ls -rt cs*log)
echo "$log_list" > log-list.txt
echo -e "$dir_name:\n$log_list\n"
[ "$log_list" != "" ] && {
first_line=$(egrep -nr -m 1 "^$1" $log_list | head -n 1)
[ "$first_line" != "" ] && {
first_line_file_name=$(awk -F':' '{print $1}' <<< "$first_line")
first_line_start_num=$(awk -F':' '{print $2}' <<< "$first_line")
[ "$first_line_file_name" != "" ] && {
[ $first_line_start_num -gt 1 ] && {
echo "trim log: sed -i \"1,${first_line_start_num}d\" $first_line_file_name"
sed -i "1,${first_line_start_num}d" $first_line_file_name
}
}
echo "数据统计:"
# ...
}
}
}
}
【】scp到服务器时即使服务器关闭了DNS还是需要等待较久才会跳出输入密码的提示
alias pwscp='scp -o PreferredAuthentications=password'
【】awk 列求和
gawk '{if (arr[$4]) {arr[$4]=arr[$4]+strtonum($2);} else {arr[$4]=strtonum($2);}}END{for(idx in arr){print idx " " arr[idx]}}' not_free.log | sort -k 2 -nr
【】sort命令详解
https://www.cnblogs.com/51linux/archive/2012/05/23/2515299.html
本文来自博客园,作者:LiYanbin,转载请注明原文链接:https://www.cnblogs.com/stellar-liyanbin/p/17666973.html