Skip to content

Commit b2d1e65

Browse files
committed
This goes through the server list and pings the machine, if it is up it will load the putty session, if its not it will notify you.
1 parent 1ab5159 commit b2d1e65

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

powerdown_startup.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Script Name : powerdown_startup.py
2+
# Author : Craig Richards
3+
# Created : 05th January 2012
4+
# Last Modified :
5+
# Version : 1.0
6+
7+
# Modifications :
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.
10+
11+
import os # Load the Library Module
12+
import subprocess # Load the Library Module
13+
from time import strftime # Load just the strftime Module from Time
14+
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
17+
for server in open('startup_list.txt','r'): # Read the list of servers from the list
18+
ret = subprocess.call("ping -n 3 %s" % server, shell=True,stdout=open('NUL', 'w'),stderr=subprocess.STDOUT) # Ping the servers in turn
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
21+
subprocess.Popen(('putty -load '+server)) # Load the putty session
22+
else:
23+
f.write ("%s : did not respond" % server.strip() + "\n") # Write to the logfile if the server is down
24+
25+
def linux():
26+
f = open('server_startup_'+strftime("%Y-%m-%d")+'.log', 'a') # Open the logfile
27+
for server in open('startup_list.txt'): # Read the list of servers from the list
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+
if ret == 0: # If you get a response.
30+
f.write ("%s: is alive" % server.strip() + "\n") # Print a message
31+
subprocess.Popen(['ssh', server.strip()])
32+
else:
33+
f.write ("%s: did not respond" % server.strip() + "\n")
34+
35+
# End of the functions
36+
37+
# Start of the Main Program
38+
39+
if os.name == "posix": # If the OS is linux...
40+
linux() # Call the linux function
41+
elif os.name in ("nt", "dos", "ce"): # If the OS is Windows...
42+
windows() # Call the windows function

0 commit comments

Comments
 (0)