fixed extensions for run-parts

This commit is contained in:
Mateusz Pstrucha committed 2020-08-12 00:24:23 +02:00
1 parent c2bc3b2f39
commit cf417969dd
6 files changed
+130 -254

No files matched your search

+87 -74
View File
@@ -1,80 +1,93 @@
#!/usr/bin/env node
const config = require('./config.json'),
ex = require('./execute'),
bar = require('./bar'),
readable = require('./readable')
#!/usr/bin/env python3
import os
import misc
var stats = {}
# MISCELLANEOUS
Promise.all([
ex('uptime -p').then(out => {
stats.uptime = out.slice(3, -1)
}),
ex('uptime').then(out => {
var [, users, a, b, c] = /(\d+) users*?, load average: (\d+\.\d+), (\d+\.\d+), (\d+\.\d+)/gm.exec(out)
stats.loads = [parseFloat(a), parseFloat(b), parseFloat(c)]
stats.users = users
}),
ex('free').then(out => {
var grep = /Mem: *?(\d+) *?(\d+) *?(\d+) *?(\d+) *?(\d+) *?(\d+)\nSwap: *?(\d+) *?(\d+) *?(\d+)/gm.exec(out)
stats.memory = {
total: grep[1],
used: grep[2],
free: grep[3],
shared: grep[4],
cache: grep[5],
available: grep[6],
}
stats.swap = {
total: grep[7],
used: grep[8],
free: grep[9]
}
}),
ex(`cat ${config.publicip}`).then(out => {
stats.public = /.* (\d+\.\d+\.\d+\.\d+)$/gms.exec(out)[1]
}).catch(err => {
stats.public = 'N/A'
}),
ex('ip addr').then(out => {
var m, r = /\d+: (\S+): .*?link\/(ether|loopback) (\S+:\S+:\S+:\S+:\S+:\S+).*?inet (\d+\.\d+\.\d+\.\d+\/\d+) /gs
stats.nics = {}
stats.nics.spaces = 0
do {
m = r.exec(out);
if (m) {
stats.nics[m[1]] = {
mac: m[3],
addr: m[4]
}
if (m[1].length > stats.nics.spaces) stats.nics.spaces = m[1].length
}
} while (m);
})
]).then(() => {
console.log()
console.log(`System is up \x1b[34m${stats.uptime}\x1b[0m`)
console.log(`${stats.users} user${stats.users == 1 ? '' : 's'} logged in`)
process.stdout.write(`CPU: `)
for (load of stats.loads) {
let color = '\x1b[32m'
if (load > 1) color = '\x1b[31m'
else if (load > 0.5) color = '\x1b[33m'
process.stdout.write(color)
process.stdout.write(load.toFixed(2) + ' ')
process.stdout.write('\x1b[0m')
}
console.log()
uptime = os.popen('uptime -p').read()
console.log(`Memory: ${readable(stats.memory.used)} MB out of ${readable(stats.memory.total)} MB\n${bar(stats.memory.used, stats.memory.total, ['\x1b[93m=', '-'])}`)
console.log(`Swap: ${readable(stats.swap.used)} MB out of ${readable(stats.swap.total)} MB\n${bar(stats.swap.used, stats.swap.total, ['\x1b[93m=', '-'])}`)
console.log()
print("System is up \x1b[34m{}\x1b[0m".format(uptime[3:-1]))
console.log(`Public IP: \x1b[34m${stats.public}\x1b[0m`)
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()
for (let nic in stats.nics) {
if (nic === 'spaces') continue
console.log(` ${nic}:${' '.repeat(stats.nics.spaces - nic.length + 1)}${stats.nics[nic].mac} - \x1b[36m${stats.nics[nic].addr}\x1b[0m`)
}
who = who.split('\n')[2:-1]
users = [0, 0]
for line in who:
line = line.split()
if line[2].startswith('tmux'):
users[1] += 1
else:
users[0] += 1
})
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]
print("CPU: ", end = '')
for load in loads:
load = float(load)
color = '\x1b[32m'
if load > 1:
color = '\x1b[31m'
else:
if load > 0.5:
color = '\x1b[33m'
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(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(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 = []
skip = False
nicNameLen = 0
for line in ip:
line = line.split()
if ':' in line[0]:
if 'UP' in line[2]:
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]])
if 'inet' in line[0]:
links[-1][-1].append(line[1].split('/'))
for eth in links:
if eth[0] == 'lo': continue
print("{}:{} {} - \x1b[36m{}/{}\x1b[0m".format(
eth[0],
" "*(nicNameLen-len(eth[0])),
eth[1][0],
eth[1][1][0],
eth[1][1][1]
))
print()
-93
View File
@@ -1,93 +0,0 @@
#!/usr/bin/env python3
import os
import misc
# MISCELLANEOUS
uptime = os.popen('uptime -p').read()
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()
who = who.split('\n')[2:-1]
users = [0, 0]
for line in who:
line = line.split()
if line[2].startswith('tmux'):
users[1] += 1
else:
users[0] += 1
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]
print("CPU: ", end = '')
for load in loads:
load = float(load)
color = '\x1b[32m'
if load > 1:
color = '\x1b[31m'
else:
if load > 0.5:
color = '\x1b[33m'
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(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(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 = []
skip = False
nicNameLen = 0
for line in ip:
line = line.split()
if ':' in line[0]:
if 'UP' in line[2]:
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]])
if 'inet' in line[0]:
links[-1][-1].append(line[1].split('/'))
for eth in links:
if eth[0] == 'lo': continue
print("{}:{} {} - \x1b[36m{}/{}\x1b[0m".format(
eth[0],
" "*(nicNameLen-len(eth[0])),
eth[1][0],
eth[1][1][0],
eth[1][1][1]
))
print()
+19 -14
View File
@@ -1,15 +1,20 @@
#!/usr/bin/env node
const config = require('./config.json'),
ex = require('./execute'),
bar = require('./bar'),
readable = require('./readable')
#!/usr/bin/env python3
import os
import misc
ex('df').then(out => {// | grep dev/sd
out.split('\n').forEach(drive => {
grep = /\/dev\/(sd[a-z]\d)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+%) (\/\S*)$/gm.exec(drive)
if(grep == null) return
console.log()
console.log(`\x1b[96m${grep[1]}\x1b[0m mounted on \x1b[34m${grep[6]}\x1b[0m \x1b[33m${readable(grep[3], 2)}GB\x1b[0m of ${readable(grep[2], 2)}GB`)
console.log(bar(grep[3], grep[2], ['\x1b[94m=', '-']))
})
})
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()
-20
View File
@@ -1,20 +0,0 @@
#!/usr/bin/env python3
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 -28
View File
@@ -1,29 +1,25 @@
#!/usr/bin/env node
const config = require('./config.json'),
ex = require('./execute'),
bar = require('./bar'),
readable = require('./readable')
#!/usr/bin/env python3
import os
import misc
ex('sensors -j').then(out => {
out = JSON.parse(out)
console.log()
console.log(`Temperatures:`)
for(let adapter in out){
console.log(` \x1b[96m${adapter}\x1b[0m`)
for(prop in out[adapter]){
if (typeof out[adapter][prop] == 'string') continue
for (let tmp in out[adapter][prop]){
if (/temp.*input/.test(tmp)){
let name = tmp.slice(0, -6),
stat = out[adapter][prop][tmp] / (out[adapter][prop][name+'_max'] || 85)
console.log(` \x1b[34m${prop}:\x1b[0m ${
stat > 1 ? '\x1b[1m\x1b[31m' :
stat > config.warn ? '\x1b[31m' :
stat > config.high ? '\x1b[93m' : ''
}${out[adapter][prop][tmp]}°C\x1b[0m`)
}
}
}
}
})
# 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)
-25
View File
@@ -1,25 +0,0 @@
#!/usr/bin/env python3
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)