1
1
# Script Name : powerdown_startup.py
2
- # Author : Craig Richards
3
- # Created : 05th January 2012
4
- # Last Modified :
5
- # Version : 1.0
2
+ # Author : Craig Richards
3
+ # Created : 05th January 2012
4
+ # Last Modified : 21th September 2017
5
+ # Version : 1.0
6
6
7
7
# Modifications :
8
8
9
- # Description : This goes through the server list and pings the machine, if it's up it will load the putty session, if its not it will notify you.
9
+ # Description : This goes through the server list and pings the machine, if it's up it will load the putty session, if its not it will notify you.
10
10
11
- import os # Load the Library Module
12
- import subprocess # Load the Library Module
11
+ import os # Load the Library Module
12
+ import subprocess # Load the Library Module
13
13
from time import strftime # Load just the strftime Module from Time
14
14
15
15
def windows (): # This is the function to run if it detects the OS is windows.
16
- f = open ('server_startup_' + strftime ("%Y-%m-%d" )+ '.log' , 'a' ) # Open the logfile
16
+ f = open ('server_startup_' + strftime ("%Y-%m-%d" )+ '.log' , 'a' ) # Open the logfile
17
17
for server in open ('startup_list.txt' ,'r' ): # Read the list of servers from the list
18
18
ret = subprocess .call ("ping -n 3 %s" % server , shell = True ,stdout = open ('NUL' , 'w' ),stderr = subprocess .STDOUT ) # Ping the servers in turn
19
19
if ret == 0 : # If you get a response.
20
- f .write ("%s: is alive, loading PuTTY session" % server .strip () + "\n " ) # Write out to the logfile
20
+ f .write ("%s: is alive, loading PuTTY session" % server .strip () + "\n " ) # Write out to the logfile
21
21
subprocess .Popen (('putty -load ' + server )) # Load the putty session
22
22
else :
23
- f .write ("%s : did not respond" % server .strip () + "\n " ) # Write to the logfile if the server is down
23
+ f .write ("%s : did not respond" % server .strip () + "\n " ) # Write to the logfile if the server is down
24
24
25
25
def linux ():
26
- f = open ('server_startup_' + strftime ("%Y-%m-%d" )+ '.log' , 'a' ) # Open the logfile
26
+ f = open ('server_startup_' + strftime ("%Y-%m-%d" )+ '.log' , 'a' ) # Open the logfile
27
27
for server in open ('startup_list.txt' ): # Read the list of servers from the list
28
28
ret = subprocess .call ("ping -c 3 %s" % server , shell = True ,stdout = open ('/dev/null' , 'w' ),stderr = subprocess .STDOUT ) # Ping the servers in turn
29
29
if ret == 0 : # If you get a response.
@@ -36,7 +36,9 @@ def linux():
36
36
37
37
# Start of the Main Program
38
38
39
- if os .name == "posix" : # If the OS is linux...
40
- linux () # Call the linux function
39
+ if os .name == "posix" : # If the OS is linux...
40
+ linux () # Call the linux function
41
41
elif os .name in ("nt" , "dos" , "ce" ): # If the OS is Windows...
42
- windows () # Call the windows function
42
+ windows () # Call the windows function
43
+ else :
44
+ print ("Not supported" )
0 commit comments