Script bugfixes for find exec delete

master
Thomas Lynch 2 years ago
parent 3c8694d308
commit 3497a5f821
No known key found for this signature in database
GPG Key ID: FBAB081F9B6E14B2
  1. 2
      posters.sh
  2. 17
      viewers.sh

@ -14,4 +14,4 @@ do
done <<< "$all_live"
# delete old posters
bash -c 'find /var/www/stream/posters/* -mmin +2 -exec rm {} \;'
bash -c 'find /var/www/stream/posters/*.jpg -mmin +2 -exec rm {} \;'

@ -7,9 +7,20 @@ timestamp_prev=$(date -d '1 min ago' +'%s')
lf_now=$(date +'%d/%b/%Y:%H:%M:' -d @$timestamp_now)
lf_prev=$(date +'%d/%b/%Y:%H:%M:' -d @$timestamp_prev)
# tail the logs and get a count of viewers per streamer
# tail the logs and get a count of viewers per streamer. the pipeline is:
# lines with hls or dash urls
# between the start and end times
# print the ip and stream stream .m3u8/mpd
# sort them
# uniq to deduplicate
# print just the stream names now
# cut off the .m3u8/mpd so we have just the name
# sort again (because ip is removed)
# uniq with counts this time
# remove non alphanumeric or space
# remove leading whitespace from uniq
viewers=`tail -n 10000 /var/log/nginx/access.log \
| grep -E 'GET /(hls|dash)/[a-z0-9]+.m3u8' \
| grep -E 'GET /(hls|dash)/[a-z0-9]+.(m3u8|mpd)' \
| grep -E "${lf_now}|${lf_prev}" \
| awk '{print $3 " " $7}' \
| sort \
@ -30,4 +41,4 @@ do
done <<< "$viewers"
# delete any not updated viewer files (no longer live)
find /var/www/stream/viewers/* -mmin +0.5 -exec rm {} \;
bash -c 'find /var/www/stream/viewers/*.txt -mmin +0.5 -exec rm {} \;'

Loading…
Cancel
Save