forked from karpathy/ulogme
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
xinput
to not depend on access to /dev/console
(root only).
Closes karpathy#34 Additional improvements and fixes: * Why use `cat`, `grep` and `wc` combined when `grep` can do all of this at once? Fixed. [shellcheck](https://www.shellcheck.net/) can make you aware of such things. * Never storge highly sensitive information like keystrokes (which potentially can contain passwords) on persistent storage. * Terminate background processes when the main process gets killed. * Updated and fixed README.md accordingly. * Removed trailing whitespace.
- Loading branch information
Showing
3 changed files
with
32 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,42 @@ | ||
#!/bin/bash | ||
|
||
|
||
# logs the key press frequency over 9 second window. Logs are written | ||
# logs the key press frequency over 9 second window. Logs are written | ||
# in logs/keyfreqX.txt every 9 seconds, where X is unix timestamp of 7am of the | ||
# recording day. | ||
|
||
LANG=en_US.utf8 | ||
|
||
helperfile="logs/keyfreqraw.txt" # temporary helper file | ||
helperfile='/dev/shm/keyfreqraw.txt' | ||
## FIXME: Still potential security risk even when not logged to persistent storage. | ||
## Maybe rewrite script in Python and count STDOUT directly and send SIGINT | ||
## after 9 seconds. | ||
|
||
mkdir -p logs | ||
|
||
trap 'kill $(jobs -p)' EXIT | ||
|
||
while true | ||
do | ||
showkey > $helperfile & | ||
PID=$! | ||
|
||
# work in windows of 9 seconds | ||
xinput test 11 > $helperfile & | ||
|
||
## In case you can not get `xinput` to work. Note that you will need to run `showkey` as root. | ||
# showkey > $helperfile & | ||
|
||
# Work in windows of 9 seconds | ||
sleep 9 | ||
kill $PID | ||
|
||
# count number of key release events | ||
num=$(cat $helperfile | grep release | wc -l) | ||
|
||
# append unix time stamp and the number into file | ||
|
||
# shellcheck disable=SC2046 | ||
kill $(jobs -rp) | ||
# shellcheck disable=SC2046 | ||
wait $(jobs -rp) 2>/dev/null | ||
|
||
# Count number of key release events | ||
num="$(grep --count release "$helperfile")" | ||
|
||
# Append unix time stamp and the number into file | ||
logfile="logs/keyfreq_$(python rewind7am.py).txt" | ||
echo "$(date +%s) $num" >> $logfile | ||
echo "$(date +%s) $num" >> "$logfile" | ||
echo "logged key frequency: $(date) $num release events detected into $logfile" | ||
|
||
done | ||
|
||
done |
This file contains 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