Show a listing of last logged in current user.
Last active
April 3, 2020 06:39
-
-
Save kou1okada/abb626fcc9abcebe213e993f922e0812 to your computer and use it in GitHub Desktop.
last4cygwin - show a listing of last logged in current user
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
last4cygwin |
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
#!/usr/bin/env bash | |
utmp="$(mktemp -u)" | |
wtmp="$(cygpath -w "$utmp")" | |
src="$(cat <<-EOD | |
-Command | |
Get-EventLog Security | | |
Where-Object { \$_.InstanceId -eq 4672 } |% { | |
\$x=\$_ | |
\$_.Message | | |
sls "アカウント名.*(\${Env:USERNAME})" |% { | |
"\$(\$x.TimeGenerated.ToString("yyyy-MM-dd HH:mm:ss")) \$(\$_.Matches.Groups[1].Value)" | |
} | |
} >"$wtmp" | |
echo "$wtmp" | |
ls "$wtmp" | |
EOD | |
)" | |
src="${src//\"/\\\"}" | |
powershell -Command Start-Process -WindowStyle Hidden -Verb RunAs powershell \'"${src}"\' | |
progress_count=0 | |
progress_char=( '-' '\' '|' '/' ) | |
function progress_init () | |
{ | |
: | |
} | |
function progress_update () | |
{ | |
printf "%s\r" "${progress_char[progress_count++ % 4]}" | |
} | |
function progress_end () | |
{ | |
printf " \r" | |
} | |
n=0 | |
progress_update | |
t1="$(date "+%F %T.%N %z")" | |
#echo "$t1" | |
for i in {1..10}; do | |
sleep 0.5 | |
progress_update | |
t2="$(stat -c %y "$utmp")" | |
# echo "$t2" | |
[ "$t1" = "$t2" ] && let n++ || n=0 | |
(( 2 < n )) && break | |
t1="$t2" | |
done | |
progress_end | |
iconv -f UTF-16LE "$utmp" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment