You've already forked scripts-random
33 lines
828 B
Bash
33 lines
828 B
Bash
#!/bin/bash
|
|
|
|
# Cabecera
|
|
printf "%-25s %-25s %-20s\n" "Encendido" "Apagado" "Tiempo activo"
|
|
printf "%-25s %-25s %-20s\n" "----------" "--------" "--------------"
|
|
|
|
# Usamos `tac` para invertir el orden de `last -x`
|
|
last -x | tac | awk '
|
|
/reboot/ {
|
|
boot = $6" "$7" "$8
|
|
next
|
|
}
|
|
/shutdown/ && boot != "" {
|
|
shut = $6" "$7" "$8
|
|
cmd1 = "date -d \""boot"\" +%s"; cmd1 | getline t1; close(cmd1);
|
|
cmd2 = "date -d \""shut"\" +%s"; cmd2 | getline t2; close(cmd2);
|
|
delta = t2 - t1
|
|
if (delta > 0) {
|
|
h = int(delta / 3600)
|
|
m = int((delta % 3600) / 60)
|
|
s = delta % 60
|
|
printf "%-25s %-25s %02d:%02d:%02d\n", boot, shut, h, m, s
|
|
total += delta
|
|
}
|
|
boot = ""
|
|
}
|
|
END {
|
|
h = int(total / 3600)
|
|
m = int((total % 3600) / 60)
|
|
s = total % 60
|
|
printf "\n%-51s %02d:%02d:%02d\n", "Tiempo total encendido:", h, m, s
|
|
}'
|