

Print("The switch is pingable, let's proceed !\n") Print("Checking to see if the SAN switch is pingable\n") Print("This script allows the user to enable and disable ports on a SAN switch to see how it behaves\n") Print (deviceIP + " " + deviceUsername + " " + devicePassword)
HOW TO USE THE SUBPROCESS PYTHON LIBRARY PASSWORD
Print("The device password parameter is blank\n") Print("The device userName parameter is blank\n") Print("The device IP parameter is blank\n") Parser.add_argument("-devicePassword", help="Target device password", type=str) Parser.add_argument("-deviceUsername", help="Target device username", type=str) Parser.add_argument("-deviceIP", help="Target device IP address", type=str) Parser = argparse.ArgumentParser(description=scriptPurpose, formatter_class=RawTextHelpFormatter) ScriptPurpose = 'This script enables and disables the SAN switches' Print("The name of this script is: " + scriptName)

Here is the an example of argparse being used in one of the scripts def runMain():

Print("Exiting the program now, have a great day !\n") User_input = input("Please select an option for which your heart desires.\n")ĭeviceIP = raw_input("Enter the IP address for the device")ĭeviceUsername = raw_input("Enter the username for the device")ĭevicePassword = raw_input("Enter the password for the device") ScriptPurpose = 'This script is the top-level module that can invoke any script the user desires !\n' Print("The name of this script: " + scriptName + "\n") Unfortunately I am using 2.7.16 because of this weird company thing and I've been trying to get my managers to know that 2.7 is going to be unsupported soon but that's not relevant as of now. The problem is that these scripts are run in the command line using argparse, so that's the issue. Subprocess intends to replace several other, older modules and functions, like: os.system, os.spawn, os.popen, popen2. input/output/error pipes, and obtain their return codes. This is my first time using the subprocces library and I don't know if I'm calling these scripts right. The subprocess module allows us to spawn processes, connect to their. San_cable_test.py: error: unrecognized arguments: -deviceIP 172.1.1.1 -deviceUsername myUsername -devicePassword myPassword San_cable_test.py: error: unrecognized arguments: 172.1.1.1 myUsername myPassword The name of this script is: San_cable_test.py I tried it two different ways and I'll show the tracebacks: usage: San_cable_test.py However, when I run the program and select one of the options and get the user arguments, I get a error: unrecognized arguments: So far I have created a top-level python file that is set up to call two python scripts to start with that the user can enter. It is important to note that my python scripts contain command-line argparse arguments for it to run, for example: python San_cable_test.py -deviceIP 172.1.1.1 -deviceUsername myUsername -devicePassword myPassword I have been advised to use the subprocess library and this seems to make the most sense for what I want to do. I want to create one top-level python file that can run other python scripts so the user can decide which scripts they want to run. So essentially I have 15 or so scripts that can connect to various networking devices using an SSH library.
