-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail_status.sh
executable file
·36 lines (26 loc) · 1.01 KB
/
mail_status.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
recipient=$1
# Create temporary file
tmpFile=$(mktemp)
echo "Status report created at $(date)" > $tmpFile
echo -e "\n[General Info]" >> $tmpFile
echo "Hostname: $(hostname)" >> $tmpFile
echo "OS type: $(cat /proc/sys/kernel/ostype)" >> $tmpFile
echo "Kernel version: $(cat /proc/sys/kernel/osrelease)" >> $tmpFile
echo "System uptime: $(uptime)" >> $tmpFile
echo -e "\n[IPs]" >> $tmpFile
echo "$(ip addr show scope global | grep inet | cut -d' ' -f6 | cut -d/ -f1)" >> $tmpFile
echo -e "\n[RAM usage]" >> $tmpFile
free -h >> $tmpFile
echo -e "\n[Mounted disks]" >> $tmpFile
df -h >> $tmpFile
echo -e "\n[Available updates]" >> $tmpFile
apt-get -q update > /dev/null
apt-get -q -s upgrade | grep --color=never -e "^The following packages" -e "^ " >> $tmpFile
echo -e "\n[Services]" >> $tmpFile
netstat -tulpn >> $tmpFile 2>&1
echo -e "\n[Running Processes]" >> $tmpFile
top -bn 1 >> $tmpFile
# Send email
mail -a"From: $(whoami)@$(hostname)" -s "Status report for: $(hostname)" $recipient <$tmpFile
rm $tmpFile