Ubuntu – How to generate uptime monthly report in linux

command lineuptime

I wanted to send monthly uptime report to my clients through email. Will any one help me how to generate monthly report.

Best Answer

As a quick note to the excellent reply made by Rinzwind about Tuptime.

The package is available in the offical repository, so you can install with:

# apt-get install tuptime

Supossing that you send the report the day 1 of each month, these are the steps:

Get the timestamp of the first day of one month ago from 00:00 hours:

$ date -d "-1 month 00:00" +%s
1514761200

Get the timestamp of the last day of the previous month from 23:59 hours:

$ date -d "this month -1 second 00:00" +%s
1517439599

Use this numbers with the tsince and tuntil arguments:

$ tuptime --tsince 1514761200 --tuntil 1517439599 
System startups:    25   since   00:00:00 01/01/18   until   23:59:59 31/01/18
System shutdowns:   24 ok   -   1 bad
System uptime:      4.84 %   -   1 day, 12 hours, 0 minutes and 24 seconds
System downtime:    95.16 %   -   29 days, 11 hours, 59 minutes and 36 seconds
System life:        31 days, 0 hours, 0 minutes and 0 seconds

Largest uptime:     3 hours, 37 minutes and 41 seconds   from   19:00:15 16/01/18
Shortest uptime:    1 minute and 5 seconds   from   16:40:13 19/01/18
Average uptime:     1 hour, 26 minutes and 25 seconds

Largest downtime:   4 days, 9 hours, 48 minutes and 21 seconds   from   14:11:38 27/01/18
Shortest downtime:  11 seconds   from   16:40:02 19/01/18
Average downtime:   1 day, 4 hours, 19 minutes and 11 seconds

Current uptime:     48 minutes and 19 seconds   since   18:50:03 01/02/18

Now you can get this report, or one of the others available like the table or list format, and send it to the clients.

Related Question