Skip to content

Instantly share code, notes, and snippets.

@jcla1
Last active December 23, 2015 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcla1/6562332 to your computer and use it in GitHub Desktop.
Save jcla1/6562332 to your computer and use it in GitHub Desktop.
Cron and Applescript files for personal tracking
[submodule "running_programs"]
path = running_programs
url = https://gist.github.com/6554497.git
[submodule "chrome_status"]
path = chrome_status
url = https://gist.github.com/6525572.git
[submodule "frontApp"]
path = frontApp
url = https://gist.github.com/6522769.git
# Log computer activity to daily log file
# by Joseph Adams
# MIT Licensed
CHROME_STATUS="data/misc/cron/chrome_status/chrome_status.applescript"
RUNNING_PROGRAMS="data/misc/cron/running_programs/running_programs.applescript"
FRONT_APP="data/misc/cron/frontApp/frontApp.applescript"
LOG_FILE="data/misc/activity_log/`date +%Y%m%d`.log"
function log_activity()
{
local UTC=`date "+%s,%Z"`
local IDLE=$((`/usr/sbin/ioreg -c IOHIDSystem | sed -e '/HIDIdleTime/!{ d' -e 't' -e '}' -e 's/.* = //g' -e 'q'` / 1000000000 ))
local ACTIVE_PROGRAM=$(/usr/bin/osascript $FRONT_APP)
read CHROME_STATS ACTIVE_URL <<< `/usr/bin/osascript $CHROME_STATUS`
local PROGRAMS=$(/usr/bin/osascript $RUNNING_PROGRAMS)
echo "$UTC,$IDLE,$ACTIVE_PROGRAM,$CHROME_STATS\n$PROGRAMS\n$ACTIVE_URL" >> $LOG_FILE
#echo "`vnstat --dumpdb | grep "^d;0" | tr ";" "," | cut -d, -f 3-`" >> $LOG_FILE
}
log_activity
sleep 15
log_activity
sleep 15
log_activity
sleep 15
log_activity
0-55/5 * * * * data/misc/cron/net_usage.sh
* * * * * data/misc/cron/activity.sh
0-55/5 * * * * if [ -x /usr/local/Cellar/vnstat/1.11/bin/vnstat ] && [ `ls /usr/local/var/db/vnstat/ | wc -l` -ge 1 ]; then /usr/local/Cellar/vnstat/1.11/bin/vnstat -u; fi
LOG_FILE="data/misc/activity_log/net_`date +%Y%m%d`.log"
echo "`date "+%s,%Z"`,`/usr/local/bin/vnstat --dumpdb | grep "^d;0" | tr ";" "," | cut -d, -f 4-`" >> $LOG_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment