You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Modifications : 1.1 - 14th May 2012 - CR Changed it to use the config directory to store the server files
8
+
9
+
# Description : This script will, depending on the arguments supplied will ping the servers associated with that application group.
10
+
11
+
importos# Load the Library Module
12
+
importsubprocess# Load the Library Module
13
+
importsys# Load the Library Module
14
+
15
+
if'-h'insys.argvor'--h'insys.argvor'-help'insys.argvor'--help'insys.argv: # Help Menu if called
16
+
print'''
17
+
You need to supply the application group for the servers you want to ping, i.e.
18
+
dms
19
+
swaps
20
+
21
+
Followed by the site i.e.
22
+
155
23
+
bromley'''
24
+
sys.exit(0)
25
+
else:
26
+
27
+
if (len(sys.argv) <3): # If no arguments are passed,display the help/instructions on how to run the script
28
+
sys.exit ('\nYou need to supply the app group. Usage : '+filename+' followed by the application group i.e. \n\t dms or \n\t swaps \n then the site i.e. \n\t 155 or \n\t bromley')
29
+
30
+
appgroup=sys.argv[1] # Set the variable appgroup as the first argument you supply
31
+
site=sys.argv[2] # Set the variable site as the second argument you supply
32
+
33
+
ifos.name=="posix": # Check the os, if it's linux then
34
+
myping="ping -c 2 "# This is the ping command
35
+
elifos.namein ("nt", "dos", "ce"): # Check the os, if it's windows then
36
+
myping="ping -n 2 "# This is the ping command
37
+
38
+
if'dms'insys.argv: # If the argument passed is dms then
39
+
appgroup='dms'# Set the variable appgroup to dms
40
+
elif'swaps'insys.argv: # Else if the argment passed is swaps then
41
+
appgroup='swaps'# Set the variable appgroup to swaps
42
+
43
+
if'155'insys.argv: # If the argument passed is 155 then
44
+
site='155'# Set the variable site to 155
45
+
elif'bromley'insys.argv: # Else if the argument passed is bromley
46
+
site='bromley'# Set the variable site to bromley
47
+
48
+
filename=sys.argv[0] # Sets a variable for the script name
49
+
logdir=os.getenv("logs") # Set the variable logdir by getting the OS environment logs
50
+
logfile='ping_'+appgroup+'_'+site+'.log'# Set the variable logfile, using the arguments passed to create the logfile
51
+
logfilename=os.path.join(logdir, logfile) # Set the variable logfilename by joining logdir and logfile together
52
+
confdir=os.getenv("my_config") # Set the variable confdir from the OS environment variable - 1.2
53
+
conffile= (appgroup+'_servers_'+site+'.txt') # Set the variable conffile - 1.2
54
+
conffilename=os.path.join(confdir, conffile) # Set the variable conffilename by joining confdir and conffile together - 1.2
55
+
56
+
f=open(logfilename, "w") # Open a logfile to write out the output
57
+
forserverinopen(conffilename): # Open the config file and read each line - 1.2
58
+
ret=subprocess.call(myping+server, shell=True,stdout=f,stderr=subprocess.STDOUT) # Run the ping command for each server in the list.
59
+
ifret==0: # Depending on the response
60
+
f.write (server.strip() +" is alive"+"\n") # Write out that you can receive a reponse
61
+
else:
62
+
f.write (server.strip() +" did not respond"+"\n") # Write out you can't reach the box
63
+
64
+
print ("\n\tYou can see the results in the logfile : "+logfilename); # Show the location of the logfile
0 commit comments