
도와주세요. 서로 다른 두 날짜 범위를 사용하여 Ubuntu
원본 폴더 auth.log
와 syslog
폴더 폴더에서 일부 이벤트를 검색하려고 합니다 /var/log/
. 어떻게 해야 합니까?
내 코드는 다음과 같습니다. 날짜 범위만 있지만 그 안에 시작 날짜와 종료 날짜가 필요합니다.
#!/bin/bash
#User Input
echo -n -e "What's your Date range:"
read inputdate
#Save the search result in a file
sudo egrep "$inputdate" /var/log/auth.log > result.txt
#Display the result column wise with highlighted searching key word
column -t result.txt | more
echo -e "---------* End of Search Result! *-----------"
미리 감사드립니다.
답변1
Panki의 제안을 자세히 설명하기 위해 스크립트는 다음과 같습니다.
#!/bin/bash
#User Input
echo -n -e "What's your start date: "
read startdate
echo -n -e "What's your end date: "
read enddate
#Save the search result in a file
sed -n "/$startdate/,/$enddate/p" /var/log/auth.log > result.txt
#Display the result column wise with highlighted searching key word
column -t result.txt | more
echo -e "---------* End of Search Result! *-----------"