Merge log battery stript
This commit is contained in:
parent
da4580b38a
commit
fcc67d6b83
|
@ -1,5 +1,5 @@
|
||||||
#!/usr/bin/env bash
|
#!/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 BATTERY_PATH="$1"
|
||||||
declare -r WRITE_PATH="$2"
|
declare -r WRITE_PATH="$2"
|
||||||
|
|
||||||
|
@ -16,35 +16,31 @@ upower --dump > "$tmp_file"
|
||||||
|
|
||||||
declare system_name="$(hostname)"
|
declare system_name="$(hostname)"
|
||||||
declare current_time="$(date -u +"%Y-%m-%d %H:%M:%S UTC")"
|
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 }
|
BEGIN { b = "'"$BATTERY_PATH"'"; t=0 }
|
||||||
|
|
||||||
|
t && (match($0, /Device:/) || match($0, /Daemon:/)) {
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
match($0, b) { t=1 }
|
match($0, b) { t=1 }
|
||||||
|
|
||||||
t && match($0, /energy:/) {
|
t && match($0, /energy:/) {
|
||||||
split($0,a," ")
|
split($0,a," ")
|
||||||
print a[2]
|
energy = a[2]
|
||||||
exit
|
}
|
||||||
}')"
|
|
||||||
declare current_percentage="$(cat "$tmp_file" | awk '
|
|
||||||
BEGIN { b = "'"$BATTERY_PATH"'"; t=0 }
|
|
||||||
|
|
||||||
match($0, b) { t=1 }
|
|
||||||
|
|
||||||
t && match($0, /percentage:/) {
|
t && match($0, /percentage:/) {
|
||||||
split($0,a," ")
|
split($0,a," ")
|
||||||
print a[2]
|
percent = a[2]
|
||||||
exit
|
}
|
||||||
}')"
|
|
||||||
declare current_state="$(cat "$tmp_file" | awk '
|
|
||||||
BEGIN { b = "'"$BATTERY_PATH"'"; t=0 }
|
|
||||||
|
|
||||||
match($0, b) { t=1 }
|
|
||||||
|
|
||||||
t && match($0, /state:/) {
|
t && match($0, /state:/) {
|
||||||
split($0,a," ")
|
split($0,a," ")
|
||||||
print a[2]
|
state = a[2]
|
||||||
exit
|
}
|
||||||
}')"
|
|
||||||
|
|
||||||
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