Bash Script to Generate System Uptime Reports on Linux
======
For some purposes you may need to collect the **[Linux system uptime][1]** report once a month.
If so, you can use one of the following **[bash scripts][2]** based on your requirements.
Why should we collect this report?
Restarting the Linux server after a certain period of time is a good practice to fix some pending issues.
It is advisable to restart once in 180 days. But this period may vary depending on your company’s policy.
If you have been running the server for a long time without restarting.
This can lead to some performance issues or memory problems on the server, which I have noticed on many servers.
These scripts provide all system uptime reports in one place.
### What is Uptime Command
uptime command will tell how long the system has been running. It gives a one line display of the following information.
The current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes.
### What Is tuptime?
[Tuptime][3] is a tool for report the historical and statistical running time of the system, keeping it between restarts. Like uptime command but with more interesting output.
### 1) Bash Script to Check Linux System Uptime
This bash script will collect all the server uptime and send the report to the given email id.
Please replace your email id instead of ours, otherwise you will not receive mails.
```
# vi /opt/scripts/system-uptime-script.sh
#!/bin/bash
> /tmp/uptime-report.out
for host in cat /tmp/servers.txt
do
echo -n "$host: "
ssh $host uptime | awk '{print $3,$4}' | sed 's/,//'