Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有允许我从/var/log/messages grep的BASH脚本吗?_Bash_Logging_Scripting_Code Organization - Fatal编程技术网

有允许我从/var/log/messages grep的BASH脚本吗?

有允许我从/var/log/messages grep的BASH脚本吗?,bash,logging,scripting,code-organization,Bash,Logging,Scripting,Code Organization,我需要一个能够从/var/log/messages中显示指定信息的脚本(如果存在,对我自己的脚本编写能力没有信心)。我需要显示特定日期、时间和协议上记录的流量(即显示10月23日12:30到12:35之间的所有不安全FTP流量)。是否有一个脚本可以做到这一点,或者是否有人能够创建一个快速简单的脚本来完成这项工作?这是我的脚本,尽管它不能完全工作: #!/bin/bash read -p "Enter month (first 3 letters): " month read -p "Ente

我需要一个能够从/var/log/messages中显示指定信息的脚本(如果存在,对我自己的脚本编写能力没有信心)。我需要显示特定日期、时间和协议上记录的流量(即显示10月23日12:30到12:35之间的所有不安全FTP流量)。是否有一个脚本可以做到这一点,或者是否有人能够创建一个快速简单的脚本来完成这项工作?

这是我的脚本,尽管它不能完全工作:

#!/bin/bash

read -p "Enter month (first 3 letters): " month

read -p "Enter day of month: " day

read -p "Enter starting time (HH:MM:SS): " stime

read -p "Enter ending time (HH:MM:SS): " ftime

read -p "Enter chain: " chain

read -p "Enter any other modifiers (TTL, SRC, DSP, SPT, DPT, IN, OUT, etc): " modifier

if [ -z "$month" ]; then
    month='IN='
fi

if [ -z "$chain" ]; then
    chain='IN='
fi

if [ -z "$modifier" ]; then
    modifier='IN='
fi

if [ -z "$stime" ] && [ -z "$ftime" ]; then

cat /var/log/messages | grep -i "$month $day" | grep -i $chain | grep -i $modifier

else

cat /var/log/messages | grep -i "$month $day" | grep -i $chain | grep -i $modifier | sed -n "/$stime/,/$ftime/p"

fi

它工作不好,但总比没有好。也许可以改进

Per,StackOverflow的范围仅限于“软件开发特有的实际、可回答的问题”。搜索日志不是软件开发独有的问题。此外,非现场资源请求(即“你能帮我找到一个做X的工具/站点/等吗?”)是标题为“某些项目仍然偏离主题”的列表中的第4项……哦,呵呵,实际上在上有一条直接适用的评论。引用:纯代码编写请求与堆栈溢出无关——我们希望这里的问题与特定的编程问题有关——但我们很乐意帮助您自己编写!告诉我们,你被困在哪里了。这也将帮助我们更好地回答您的问题。