![n 줄이 포함된 파일을 읽고 완료된 줄 수를 인쇄합니다.](https://linux55.com/image/159523/n%20%EC%A4%84%EC%9D%B4%20%ED%8F%AC%ED%95%A8%EB%90%9C%20%ED%8C%8C%EC%9D%BC%EC%9D%84%20%EC%9D%BD%EA%B3%A0%20%EC%99%84%EB%A3%8C%EB%90%9C%20%EC%A4%84%20%EC%88%98%EB%A5%BC%20%EC%9D%B8%EC%87%84%ED%95%A9%EB%8B%88%EB%8B%A4..png)
다음 bash 스크립트를 사용하여 파일의 활성 호스트를 확인하고 있습니다.
echo "Checking for 200 status code.."
cat $1 | sort -u | while read line; do
if [ $(curl -I -s "https://$line" -o /dev/null -w "%{http_code}\n") = 200 ]
then
echo $line >> livedomains
else
echo $line >> otherdomains
fi
done < $1
코드는 정상적으로 작동합니다. 확인해야 할 남은 행 수(url)를 사용자에게 알리기 위해 잠시 후 확인된 행 수(url)를 인쇄하는 것이 필요합니다.
답변1
#!/bin/bash
# update status after step seconds or greater
step=5
count=0
echo "Checking for 200 status code.."
start=$(date +'%s')
sort -u "$1" | while read line; do
http_status=$(curl -I -s "https://$line" -o /dev/null -w "%{http_code}\n")
case "$http_status" in
200)
echo "$line" >> livedomains
;;
302)
echo "$line" >> redirecteddomains
;;
*)
echo "$line" >> otherdomains
esac
((count++))
now=$(date +'%s')
if [ "$start" -le "$((now - step))" ]; then
start=$now
echo "completed: $count"
fi
done
업데이트 간격은 5초로 설정되어 있으며, 120초로 변경할 수 있습니다.
편집하다:나는 마음을 바꾸고 대신 카운터 변수를 사용했습니다 wc
.
추가 변경 사항:
#!/bin/bash
첫 번째 줄에 shebang을 추가했습니다.< $1
입력의 마지막 행 제거 (그렇지 않으면 정렬되지 않음)- 몇 가지 인용문을 추가했습니다