Merge log battery stript
This commit is contained in:
parent
1af17f2525
commit
338eb02668
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
# Look through `upower --dump` to set this variable
|
||||
# Look through `upower --dump` to set the battery path variable
|
||||
declare -r BATTERY_PATH="$1"
|
||||
declare -r WRITE_PATH="$2"
|
||||
|
||||
|
@ -16,35 +16,31 @@ upower --dump > "$tmp_file"
|
|||
|
||||
declare system_name="$(hostname)"
|
||||
declare current_time="$(date -u +"%Y-%m-%d %H:%M:%S UTC")"
|
||||
declare current_power="$(cat "$tmp_file" | awk '
|
||||
|
||||
upower --dump | awk '
|
||||
BEGIN { b = "'"$BATTERY_PATH"'"; t=0 }
|
||||
|
||||
t && (match($0, /Device:/) || match($0, /Daemon:/)) {
|
||||
exit
|
||||
}
|
||||
|
||||
match($0, b) { t=1 }
|
||||
|
||||
t && match($0, /energy:/) {
|
||||
split($0,a," ")
|
||||
print a[2]
|
||||
exit
|
||||
}')"
|
||||
declare current_percentage="$(cat "$tmp_file" | awk '
|
||||
BEGIN { b = "'"$BATTERY_PATH"'"; t=0 }
|
||||
|
||||
match($0, b) { t=1 }
|
||||
energy = a[2]
|
||||
}
|
||||
|
||||
t && match($0, /percentage:/) {
|
||||
split($0,a," ")
|
||||
print a[2]
|
||||
exit
|
||||
}')"
|
||||
declare current_state="$(cat "$tmp_file" | awk '
|
||||
BEGIN { b = "'"$BATTERY_PATH"'"; t=0 }
|
||||
|
||||
match($0, b) { t=1 }
|
||||
percent = a[2]
|
||||
}
|
||||
|
||||
t && match($0, /state:/) {
|
||||
split($0,a," ")
|
||||
print a[2]
|
||||
exit
|
||||
}')"
|
||||
state = a[2]
|
||||
}
|
||||
|
||||
echo "$system_name,$current_time,$current_power,$current_percentage,$current_state" >> "$WRITE_PATH"
|
||||
END {
|
||||
print "'"${system_name},${current_time},"'"energy","percent","state
|
||||
}' >> "$WRITE_PATH"
|
||||
|
|
Loading…
Reference in a new issue