rewritten in python3
This commit is contained in:
1 parent
eae34dd1ea
commit
a18ad43132
11 files changed
+95
-62
No files matched your search
@@ -0,0 +1,3 @@
|
||||
__pycache__/
|
||||
*.js
|
||||
*.pyc
|
||||
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
echo -en '\e[32m'
|
||||
figlet $HOSTNAME -f slant;#
|
||||
echo -en "\e[0m"
|
||||
echo -en '\e[32m';
|
||||
figlet $HOSTNAME -f slant;
|
||||
echo -en "\e[0m";
|
||||
+37
-23
@@ -1,11 +1,11 @@
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import bar
|
||||
import misc
|
||||
|
||||
# MISCELLANEOUS
|
||||
|
||||
uptime = os.popen('uptime -p').read()
|
||||
|
||||
print "System is up \x1b[34m{}\x1b[0m".format(uptime[3:-1])
|
||||
print("System is up \x1b[34m{}\x1b[0m".format(uptime[3:-1]))
|
||||
|
||||
who = os.popen('echo " 15:13:23 up 10 days, 1:33, 2 users, load average: 1.01, 0.95, 0.98\nUSER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT\nmathias pts/0 10.0.1.4 15:12 1.00s 0.09s 0.00s w\nmathias pts/1 tmux(2498).%0 02Apr20 14:10m 2days 0.00s /bin/bash ./start"').read()
|
||||
|
||||
@@ -18,13 +18,15 @@ for line in who:
|
||||
else:
|
||||
users[0] += 1
|
||||
|
||||
print "{} users and {} terminals logged in".format(*users)
|
||||
print("{} users and {} terminals logged in".format(*users))
|
||||
|
||||
# HARDWARE STATS
|
||||
|
||||
loads = os.popen("uptime").read()
|
||||
loads = loads.split()[-3:]
|
||||
loads[0] = loads[0][:-1]
|
||||
loads[1] = loads[1][:-1]
|
||||
sys.stdout.write("CPU: ")
|
||||
print("CPU: ", end = '')
|
||||
for load in loads:
|
||||
load = float(load)
|
||||
color = '\x1b[32m'
|
||||
@@ -33,32 +35,43 @@ for load in loads:
|
||||
else:
|
||||
if load > 0.5:
|
||||
color = '\x1b[33m'
|
||||
sys.stdout.write('{}{} '.format(color, load))
|
||||
sys.stdout.write('\x1b[0m\n')
|
||||
|
||||
print('{}{} '.format(color, load), end = '')
|
||||
print('\x1b[0m\n', end = '')
|
||||
|
||||
free = os.popen("free").read()
|
||||
memory = free.split('\n')[1].split()
|
||||
swap = free.split('\n')[2].split()
|
||||
print "Memory: {:.1f}GB out of {:.1f}GB".format(
|
||||
float(memory[2])/(1024*1024), float(memory[1])/(1024*1024))
|
||||
print bar.bar(memory[2], memory[1], ['\x1b[93m=', '-'])
|
||||
print("Memory: {:.1f}GB out of {:.1f}GB".format(misc.gig(memory[2]), misc.gig(memory[1])))
|
||||
print(misc.bar(memory[2], memory[1], ['\x1b[93m=', '-']))
|
||||
|
||||
print "Swap: {:.1f}GB out of {:.1f}GB".format(
|
||||
float(swap[2])/(1024*1024), float(swap[1])/(1024*1024))
|
||||
print bar.bar(swap[2], swap[1], ['\x1b[93m=', '-'])
|
||||
print("Swap: {:.1f}GB out of {:.1f}GB".format(misc.gig(swap[2]), misc.gig(swap[1])))
|
||||
print(misc.bar(swap[2], swap[1], ['\x1b[93m=', '-']))
|
||||
print()
|
||||
|
||||
# NETWORK ADAPTERS LIST
|
||||
|
||||
ip = os.popen('ip addr').read()
|
||||
ip = ip.split('\n')[:-1]
|
||||
|
||||
links = []
|
||||
at = -1
|
||||
skip = False
|
||||
nicNameLen = 0
|
||||
|
||||
for line in ip:
|
||||
line = line.split()
|
||||
|
||||
if ':' in line[0]:
|
||||
if 'UP' in line[2]:
|
||||
links.append([line[1][:-1]])
|
||||
eth = line[1][:-1]
|
||||
links.append([eth])
|
||||
if len(eth) > nicNameLen:
|
||||
nicNameLen = len(eth)
|
||||
skip = False
|
||||
else:
|
||||
skip = True
|
||||
|
||||
if skip: continue
|
||||
|
||||
if 'link' in line[0]:
|
||||
links[-1].append([line[1]])
|
||||
@@ -66,13 +79,14 @@ for line in ip:
|
||||
if 'inet' in line[0]:
|
||||
links[-1][-1].append(line[1].split('/'))
|
||||
|
||||
# print links
|
||||
|
||||
for eth in links:
|
||||
if eth[0] == 'lo': continue
|
||||
|
||||
# sys.stdout.write("{}: ".format(eth[0]))
|
||||
for mac in eth[1:]:
|
||||
print mac
|
||||
# for ip in range(2, len(eth)):
|
||||
# print " {} /{}".format(eth[ip][0], eth[ip][1])
|
||||
print("{}:{} {} - \x1b[36m{}/{}\x1b[0m".format(
|
||||
eth[0],
|
||||
" "*(nicNameLen-len(eth[0])),
|
||||
eth[1][0],
|
||||
eth[1][1][0],
|
||||
eth[1][1][1]
|
||||
))
|
||||
print()
|
||||
@@ -0,0 +1,19 @@
|
||||
import os
|
||||
import misc
|
||||
|
||||
df = os.popen("df --output=source,fstype,size,used,avail,pcent,target").read()
|
||||
df = df.split('\n')
|
||||
df.pop(0)
|
||||
|
||||
for drv in df:
|
||||
if any(x in drv for x in ['drvfs', 'ext4']):
|
||||
drv = drv.split()
|
||||
print("\x1b[36m{}\x1b[0m mounted on {} {:.1f}GB of {:.1f}GB".format(
|
||||
drv[0],
|
||||
drv[6],
|
||||
misc.gig(drv[4]),
|
||||
misc.gig(drv[2])
|
||||
))
|
||||
print(misc.bar(drv[3], drv[2], ['\x1b[94m=', '-']))
|
||||
|
||||
print()
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import os
|
||||
import misc
|
||||
|
||||
# temps = os.popen("sensors -u").read()
|
||||
temps = "\ncoretemp-isa-0000\nAdapter: ISA adapter\nPackage id 0:\n temp1_input: 37.000\n temp1_max: 80.000\n temp1_crit: 85.000\n temp1_crit_alarm: 0.000\nCore 0:\n temp2_input: 35.000\n temp2_max: 80.000\n temp2_crit: 85.000\n temp2_crit_alarm: 0.000\nCore 1:\n temp3_input: 31.000\n temp3_max: 80.000\n temp3_crit: 85.000\n temp3_crit_alarm: 0.000\n\nnouveau-pci-0100\nAdapter: PCI adapter\nGPU core:\n in0_input: 0.980\n in0_min: 0.830\n in0_max: 1.000\ntemp1:\n temp1_input: 47.000\n temp1_max: 95.000\n temp1_max_hyst: 3.000\n temp1_crit: 105.000\n temp1_crit_hyst: 5.000\n temp1_emergency: 135.000\n temp1_emergency_hyst: 5.000"
|
||||
temps = temps.split('\n')
|
||||
lastline = False
|
||||
out = ""
|
||||
|
||||
for line in temps:
|
||||
# print(repr(lastline), repr(line))
|
||||
if lastline == '':
|
||||
out += line+'\n'
|
||||
lastline = line
|
||||
|
||||
if 'temp' in line and 'input' in line:
|
||||
line = line.split()
|
||||
out += " {} {}{:.1f}\x1b[0m\n".format(
|
||||
line[0],
|
||||
'\x1b[91m' if float(line[1])>80 else '\x1b[93m' if float(line[1])>65 else '\x1b[92m',
|
||||
float(line[1])
|
||||
)
|
||||
|
||||
print(out)
|
||||
@@ -1,9 +0,0 @@
|
||||
module.exports = function bar(used, total, chars = ['#', '-'], max = 40) {
|
||||
|
||||
var percent = used / total,
|
||||
len = Math.round(percent * max),
|
||||
rest = max - len
|
||||
|
||||
percent = (percent * 100).toFixed(1)
|
||||
return ` ${percent}%${' '.repeat(6-percent.length)}[${chars[0].repeat(len)}\x1b[0m${chars[1].repeat(rest)}\x1b[0m] `
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"publicip": "/home/mathias/git/ovh-dynhost/logs/short.log",
|
||||
"theme": "\\e[32m",
|
||||
"hostname": "odin",
|
||||
"temps": {
|
||||
"warn": 0.85,
|
||||
"high": 0.6
|
||||
},
|
||||
"pm2_user": "mathias"
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
const { exec } = require('child_process')
|
||||
|
||||
module.exports = function ex(com) {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(com, (err, stdout, stderr) => {
|
||||
if (stderr) reject(stderr)
|
||||
resolve(stdout)
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -1,15 +1,15 @@
|
||||
#!/bin/bash
|
||||
cp * /etc/update-motd.d/
|
||||
cp *.py /etc/update-motd.d/
|
||||
|
||||
chmod -x /etc/update-motd.d/*
|
||||
|
||||
chmod +x /etc/update-motd.d/00-header
|
||||
chmod +x /etc/update-motd.d/05-logo
|
||||
chmod +x /etc/update-motd.d/10-uptime
|
||||
chmod +x /etc/update-motd.d/18-mounts
|
||||
chmod +x /etc/update-motd.d/19-temps
|
||||
chmod +x /etc/update-motd.d/20-services
|
||||
chmod +x /etc/update-motd.d/22-pm2
|
||||
chmod +x /etc/update-motd.d/10-uptime.py
|
||||
chmod +x /etc/update-motd.d/18-mounts.py
|
||||
chmod +x /etc/update-motd.d/19-temps.py
|
||||
# chmod +x /etc/update-motd.d/20-services
|
||||
# chmod +x /etc/update-motd.d/22-pm2
|
||||
chmod +x /etc/update-motd.d/90-updates-available
|
||||
chmod +x /etc/update-motd.d/91-release-upgrade
|
||||
chmod +x /etc/update-motd.d/92-unattended-upgrades
|
||||
|
||||
@@ -6,3 +6,6 @@ def bar(used, total, chars=['#', '-'], max=40):
|
||||
rest = max - len
|
||||
|
||||
return " {:.1f}% {}[{}\x1b[0m{}\x1b[0m]".format(percent*100, 'a' if percent>=1 else (' ' if percent >=0.1 else ' '), chars[0]*len, chars[1]*rest)
|
||||
|
||||
def gig(bytes):
|
||||
return float(bytes)/(1024*1024)
|
||||
@@ -1 +0,0 @@
|
||||
module.exports = (value, level = 1) => ~~(value / Math.pow(1024, level))
|
||||
Reference in new issue
Block a user