-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackcheck
More file actions
executable file
·91 lines (72 loc) · 3.06 KB
/
Copy pathstackcheck
File metadata and controls
executable file
·91 lines (72 loc) · 3.06 KB
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
#!/usr/bin/env python
# Author: Dan Shumaker
# Date: 7/7/2011
# updated 4/24/2014 to include output of running processes
import os, optparse, sys,subprocess
def head(output):
if len(output):
cout(output.splitlines()[0])
def apc(output):
if len(output) and len(output.splitlines()) > 3:
lines = output.splitlines()
try:
i = lines.index('apc')
cout('APC' + lines[i+3])
except ValueError:
print 'APC not found'
def printcmd(printcmds, cmd):
if os.path.exists(cmd['cmd']):
out = subprocess.Popen(executable="/bin/bash", args=["%s %s" % (cmd['cmd'], cmd['par'])], shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT ).stdout.read()
if printcmds:
print "%s %s" % (cmd['cmd'] , cmd['par'])
if cmd.has_key('post'):
cmd['post'](out)
else:
cout(out)
else:
print cmd['cmd'] , "command not found"
def tail(output):
if len(output):
lines = output.splitlines()
cout(lines[len(lines)-1])
def procs(output):
if len(output):
lines = output.splitlines()
num = lines[len(lines)-1].split()[2]
cout("Processors = %d" % (int(num) + 1))
def cout(str):
if len(str):
first = str.split()[0]
second = " ".join(str.split()[1:])
print "%-15.20s %s" % (first, second)
if __name__ == "__main__":
us=""" Stack Version"""
dd=""" Print the software versions on the machine"""
parser = optparse.OptionParser(usage=us, description= dd, add_help_option=True)
parser.add_option("-p", "--print", dest="printcmds", action="store_true", help="Print the commands as well as output.", default=False)
(options, args) = parser.parse_args( )
softwares = [
{ 'cmd':'/usr/bin/lsb_release', 'par': '-d', 'post':head},
{ 'cmd':'/usr/sbin/apache2', 'par':'-v', 'post':head},
{ 'cmd':'/usr/bin/mysql', 'par': '--version', 'post':head},
{ 'cmd':'/usr/bin/php' , 'par':'-v', 'post':head},
{ 'cmd':'/usr/sbin/varnishd', 'par': '-V', 'post':head},
{ 'cmd':'/usr/bin/memcached', 'par':'-i', 'post':head},
{ 'cmd':'/usr/bin/java', 'par':'-version', 'post':head},
{ 'cmd':'/usr/bin/php', 'par':'-i', 'post':apc },
{ 'cmd':'/usr/bin/git', 'par':'--version', 'post':head},
]
hardware = [
{ 'cmd': '/bin/grep' , 'par':'"MemTotal" /proc/meminfo', 'post':head },
{ 'cmd':'/bin/grep', 'par':'"cpu cores" /proc/cpuinfo', 'post':head},
{ 'cmd':'/bin/grep', 'par':'"processor" /proc/cpuinfo', 'post':procs},
{ 'cmd':'/bin/grep', 'par':'"model name" /proc/cpuinfo', 'post':head },
{'cmd':'/bin/grep','par':'"cpu MHz" /proc/cpuinfo', 'post':head}]
print "\n\n=====SOFTWARE======="
for software in softwares:
printcmd(options.printcmds,software)
print "\n\n=====HARDWARE======="
for metal in hardware:
printcmd(options.printcmds,metal)
print "\n\n===== RUNNING ======"
os.system('ps waux | egrep "apache|memcache|varnish|java" | egrep -v egrep')