-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesk
More file actions
executable file
·40 lines (31 loc) · 750 Bytes
/
desk
File metadata and controls
executable file
·40 lines (31 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
# desk log (this should eventually control the standing desk)
# by tlehman at 1405703473
log_filename="$HOME/sync/data/standing_desk_log.csv"
function create_log_file_if_not_exists {
if [ ! -e $log_filename ]
then
echo "timestamp,state" > $log_filename
fi
}
function log_new_state {
create_log_file_if_not_exists
local state=$1
local timestamp=$(date +"%Y-%m-%dT%H:%M:%S")
echo "$timestamp,$state" >> $log_filename
}
function show_log {
create_log_file_if_not_exists
echo "timestamp state"
awk < $log_filename -F, 'NR > 1 {print $1" "$2}' | tail -5
}
if [ $1 = "up" ] || [ $1 = "down" ]
then
log_new_state $1
elif [ $1 = "log" ]
then
show_log
else
echo "Invalid command: $1"
exit 1
fi