-
Notifications
You must be signed in to change notification settings - Fork 0
/
status
executable file
·147 lines (134 loc) · 3.96 KB
/
status
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/sh
# stateSRV - getSTATUS/writeJSON
# VARS & CONF
CURDIR=$(dirname $0)
CONF="$CURDIR/conf/server-client.conf"
. $CONF
##########################################
## N O # C H A N G E # F R O M # H E R E #
##########################################
# DATE & TIME
DATE_TIME=${DATETIMECMD}
# OS + HOSTNAME
OS1=${OSCMD}
HOSTNAME=${HOSTNAMECMD}
# LAST LOGINS
LAST1=`last -2 -a | awk 'NR==2{print $3}'` # weekday
LAST2=`last -2 -a | awk 'NR==2{print $5}'` # day
LAST3=`last -2 -a | awk 'NR==2{print $4}'` # month
LAST4=`last -2 -a | awk 'NR==2{print $6}'` # time
LAST5=`last -2 -a | awk 'NR==2{print $10}'` # remote
LASTLOGINS="$LAST5 => $LAST1.$LAST2.$LAST3 $LAST4"
# UPTIME
UP0=`cut -d. -f1 /proc/uptime`
UP1=$(($UP0/86400)) # days
UP2=$(($UP0/3600%24)) # hours
UP3=$(($UP0/60%60)) # minutes
UP4=$(($UP0%60)) # seconds
# LOADAVERAGE
LOAD1=`cat /proc/loadavg | awk '{print $1}'` # Letzte Minute
LOAD2=`cat /proc/loadavg | awk '{print $2}'` # Letzte 5 Minuten
LOAD3=`cat /proc/loadavg | awk '{print $3}'` # Letzte 15 Minuten
# TEMPERATURE
#TEMP0=`cut -d. -f1 /sys/devices/platform/sunxi-i2c.0/i2c-0/0-0034/temp1_input`
#TEMP=$(($TEMP0/1000)) #Temperatur Dezimal
TEMP=$TEMPCMD
# STORAGE / HDD
if [ -z $DEVNAME1 ]
then
STORAGEsum1="---"
STORAGEused1="---"
STORAGEfree1="---"
else
STORAGEsum1=`df -h | grep $DEVNAME1 | awk '{print $2}'` # Gesamtspeicher
STORAGEused1=`df -h | grep $DEVNAME1 | awk '{print $3}'` # Belegt
STORAGEfree1=`df -h | grep $DEVNAME1 | awk '{print $4}'` # Frei
fi
if [ -z $DEVNAME2 ]
then
STORAGEsum2="---"
STORAGEused2="---"
STORAGEfree2="---"
else
STORAGEsum2=`df -h | grep $DEVNAME2 | awk '{print $2}'` # Gesamtspeicher
STORAGEused2=`df -h | grep $DEVNAME2 | awk '{print $3}'` # Belegt
STORAGEfree2=`df -h | grep $DEVNAME2 | awk '{print $4}'` # Frei
fi
if [ -z $DEVNAME3 ]
then
STORAGEsum3="---"
STORAGEused3="---"
STORAGEfree3="---"
else
STORAGEsum3=`df -h | grep $DEVNAME3 | awk '{print $2}'` # Gesamtspeicher
STORAGEused3=`df -h | grep $DEVNAME3 | awk '{print $3}'` # Belegt
STORAGEfree3=`df -h | grep $DEVNAME3 | awk '{print $4}'` # Frei
fi
# RAM / MEMORY
RAM1=`free -h | grep 'Mem' | awk '{print $2}'` # Total
RAM2=`free -h | grep 'Mem' | awk '{print $3}'` # Used
RAM3=`free -h | grep 'Mem' | awk '{print $4}'` # Free
RAM4=`free -h | grep 'Swap' | awk '{print $3}'` # Swap used
# NETWORK / IPs
if [ -z "$LANIPCMD" ]
then
IP_LAN="---"
else
IP_LAN=$LANIPCMD
fi
if [ -z "$WLANIPCMD" ]
then
IP_WLAN="---"
else
IP_WLAN=$WLANIPCMD
fi
if [ -z "$WANIPCMD" ]
then
IP_WAN="---"
else
IP_WAN=$WANIPCMD
fi
# OUTPUT AS JSON
NEWLINETAB="\n\t"
NEWLINETABTAB="\n\t\t"
TAB="\t"
echo "[{"
echo "$TAB\"GENERATED_AT\": \"$DATE_TIME\","
echo "$TAB\"HOSTNAME\": \"$HOSTNAME\","
echo "$TAB\"LASTLOGINS\": [ \"$LASTLOGINS\"],"
echo "$TAB\"UPTIME\": {"
echo "$TAB$TAB\"DAYS\": \"$UP1\","
echo "$TAB$TAB\"HOURS\": \"$UP2\","
echo "$TAB$TAB\"MINUTES\": \"$UP3\""
echo "$TAB},"
echo "$TAB\"LOADAVG\": [ \"$LOAD1\", \"$LOAD2\", \"$LOAD3\"],"
echo "$TAB\"CPU_TEMPERATURE\": [ \"$TEMP\" ],"
echo "$TAB\"STORAGE\": { "
echo "$TAB$TAB\"STORAGE1\": {"
echo "$TAB$TAB$TAB\"SUM\": \"$STORAGEsum1\","
echo "$TAB$TAB$TAB\"USED\": \"$STORAGEused1\","
echo "$TAB$TAB$TAB\"FREE\": \"$STORAGEfree1\""
echo "$TAB$TAB},"
echo "$TAB$TAB\"STORAGE2\": {"
echo "$TAB$TAB$TAB\"SUM\": \"$STORAGEsum2\","
echo "$TAB$TAB$TAB\"USED\": \"$STORAGEused2\","
echo "$TAB$TAB$TAB\"FREE\": \"$STORAGEfree2\""
echo "$TAB$TAB},"
echo "$TAB$TAB\"STORAGE3\": {"
echo "$TAB$TAB$TAB\"SUM\": \"$STORAGEsum3\","
echo "$TAB$TAB$TAB\"USED\": \"$STORAGEused3\","
echo "$TAB$TAB$TAB\"FREE\": \"$STORAGEfree3\""
echo "$TAB$TAB}"
echo "$TAB},"
echo "$TAB\"RAM\": {"
echo "$TAB$TAB\"SUM\": \"$RAM1\","
echo "$TAB$TAB\"USED\": \"$RAM2\","
echo "$TAB$TAB\"FREE\": \"$RAM3\","
echo "$TAB$TAB\"SWAP\": \"$RAM4\""
echo "$TAB},"
echo "$TAB\"NETWORK\": {"
echo "$TAB$TAB\"LAN\": \"$IP_LAN\","
echo "$TAB$TAB\"WLAN\": \"$IP_WLAN\"",
echo "$TAB$TAB\"WAN\": \"$IP_WAN\""
echo "$TAB}"
echo "}]"