![Ubuntu/Linux에서 서로 다른 두 날짜를 사용하여 검색하는 방법은 무엇입니까?](https://linux55.com/image/175601/Ubuntu%2FLinux%EC%97%90%EC%84%9C%20%EC%84%9C%EB%A1%9C%20%EB%8B%A4%EB%A5%B8%20%EB%91%90%20%EB%82%A0%EC%A7%9C%EB%A5%BC%20%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC%20%EA%B2%80%EC%83%89%ED%95%98%EB%8A%94%20%EB%B0%A9%EB%B2%95%EC%9D%80%20%EB%AC%B4%EC%97%87%EC%9E%85%EB%8B%88%EA%B9%8C%3F.png)
도와주세요. 서로 다른 두 날짜 범위를 사용하여 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! *-----------"