Created
November 14, 2024 11:57
-
-
Save avengerx/813a1b5112232e5c563925db918baf8d to your computer and use it in GitHub Desktop.
Simple shell script to help flushing IIS logs on Windows/cygwin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| if ! net session > /dev/null 2>&1; then | |
| echo "This tool must be run under Administrator privileges." | |
| exit 1 | |
| fi | |
| function flush() { | |
| netsh http flush logbuffer | |
| } | |
| function burst() { | |
| local resp i | |
| if [ "${1}" == keypress ]; then | |
| echo -n "Flushing until keypress: " | |
| while true; do | |
| flush > /dev/null 2>&1 | |
| echo -n "." | |
| if read -sn1 -t1 resp; then | |
| echo ", key pressed. Interrupting." | |
| return 0 | |
| fi | |
| done | |
| elif [[ "${1}" =~ ^[0-9]+$ ]]; then | |
| echo -n "Flushing every second, ${1} times: " | |
| for ((i=0; i<${1}; i++)); do | |
| flush > /dev/null 2>&1 | |
| echo -n "." | |
| sleep 1 | |
| done | |
| echo " done flushing." | |
| return 0 | |
| else | |
| echo "Invalid or missing argument to burst()." | |
| return 1 | |
| fi | |
| } | |
| while true; do | |
| echo -n "Let's flush IIS logs: | |
| b) burst of 10 times over 10 seconds | |
| B) burst of 60 times over 1 minute | |
| x) flush every second until a key is pressed | |
| q) quit | |
| Any other key) flush once | |
| > " | |
| read -sn1 resp | |
| case "${resp}" in | |
| b) echo "burst 10x over 10s"; burst 10;; | |
| B) echo "burst 60x over 60s"; burst 60;; | |
| x) echo "keep flushing until keypress"; burst keypress;; | |
| q) echo "quit."; break;; | |
| *) flush;; | |
| esac | |
| done |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Motivation for this script is to help flush IIS logs when debugging applications where, for instance, we want to log errors/warnings (using
response.appendToLog()) to IIS logs.Especially in light traffic environments like the development workstations, IIS usually takes a long time to flush requests to their logfiles in
c:/inetpub/logs/LogFiles/W3SVC<N>/u_ex<date>.log. This script helps "bursting" the flush interval when we want to immediately check the outcome of a request IIS handled, e.g. by monitoring the log file.This was produced and tested in cygwin environment. The script can be copied to somewhere in path so it can be run just by typing
iis-log-flusher.shin the command prompt.This script probably works in git-bash-here (from git for windows) and WSL.