You've already forked scripts-random
Add new script
This commit is contained in:
32
01_bash/calculate_workhours_pc.sh
Normal file
32
01_bash/calculate_workhours_pc.sh
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/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
|
||||
}'
|
||||
Reference in New Issue
Block a user