FreeKill/docs/misc/calcDailyLogin.sh

30 lines
1.2 KiB
Bash
Raw Normal View History

#!/bin/bash
# 用于统计新月杀日活的脚本,可以写入定时任务。
# 我自己是把数据库文件在这个目录创了符号链接总之确保这里存在那个数据库可以手动cd
# cd ~
SQLITE_CMD="sqlite3 users.db -readonly -list -batch -bail -cmd "
SEL_REG="SELECT count() FROM usergameinfo WHERE date(registerTime, 'unixepoch', 'localtime') >= date('now', 'localtime', 'start of day') AND date(registerTime, 'unixepoch', 'localtime') < date('now', 'localtime', 'start of day', '+1 days');"
SEL_LOG="SELECT count() FROM usergameinfo WHERE date(lastLoginTime, 'unixepoch', 'localtime') >= date('now', 'localtime', 'start of day') AND date(lastLoginTime, 'unixepoch', 'localtime') < date('now', 'localtime', 'start of day', '+1 days');"
i=0
# 数据库可能被锁定,需要循环
false # 令$?为1不知道怎么写do while循环
while [ 0 -ne $? ]; do
sleep 0.3
i=$[i+1]
if [ $i -ge 30 ]; then exit; fi
REG_COUNT=$($SQLITE_CMD "$SEL_REG" < /dev/null)
done
false
while [ 0 -ne $? ]; do
sleep 0.3
i=$[i+1]
if [ $i -ge 30 ]; then exit; fi
LOG_COUNT=$($SQLITE_CMD "$SEL_LOG" < /dev/null)
done
echo "$(date +'%Y-%m-%d'),${REG_COUNT},${LOG_COUNT}" >> loginInfo.csv