11# Script Name : pscheck.py
22# Author : Craig Richards
33# Created : 19th December 2011
4- # Last Modified :
5- # Version : 1.0
4+ # Last Modified : 17th June 2013
5+ # Version : 1.1
66
7- # Modifications :
7+ # Modifications : 1.1 - 17/06/13 - CR - Changed to functions, and check os before running the program
88
99# Description : Process check on Nix boxes, diplsay formatted output from ps command
1010
1111import commands , os , string
1212
13- program = raw_input ("Enter the name of the program to check: " )
13+ def ps ():
14+ program = raw_input ("Enter the name of the program to check: " )
1415
15- try :
16+ try :
1617 #perform a ps command and assign results to a list
1718 output = commands .getoutput ("ps -f|grep " + program )
1819 proginfo = string .split (output )
2425 Process ID:\t \t " , proginfo [1 ], "\n \
2526 Parent process ID:\t " , proginfo [2 ], "\n \
2627 Time started:\t \t " , proginfo [4 ]
27- except :
28+ except :
2829 print "There was a problem with the program."
2930
30-
31+ def main ():
32+ if os .name == "posix" : # Unix/Linux/MacOS/BSD/etc
33+ ps () # Call the function
34+ elif os .name in ("nt" , "dos" , "ce" ): # if the OS is windows
35+ print "You need to be on Linux or Unix to run this"
36+
37+
38+ if __name__ == '__main__' :
39+ main ()
0 commit comments