06-22-2015 05:06 AM - edited 03-08-2019 12:38 AM
hello,
I tried to use some python basic scripts on N5500 (NX-OS 7.0.5) ;
the only command to run such a script is : "source ushow-n5K.py" after copying "ushow-n5K.py" python script into bootflash:/scripts sub-directory of the N5K Bootflash ;
When I try to run this same script via the documented command and any variant (with "ushow-n5K.py" copied into bootflash: root directory) :
python ushow-n5K.py
or python bootflash:ushow-n5K.py
or python bootflash:/ushow-n5K.py
or python bootflash://ushow-n5K.py
or python bootflash:///ushow-n5K.py
or python /bootflash/ushow-n5K.py
or python followed by any character string
the result is the same as simply entering python with no parameter, i.e. the interactive Python mode is started as shown below :
Nexus-5K# python
Copyright (c) 2001-2012 Python Software Foundation; All Rights Reserved
Nexus-5K# >>>
I have also tried such a test by copying the python script into bootflash:/scripts directory and entering commands such as "python bootflash:/scripts/ushow-n5K.py and all variants
in all cases, the script filename entered after "python" command seems ignored
Any idea ?
thanks in advance
09-28-2015 12:19 PM
You are correct when, in the start of your question, you say that the only command to run a python script in NX-OS 7.0.5 is:
source filename.py
where "filename.py" is the name of the python file you are running.
---------------
The reason you are encountering the Interactive Python Mode (Nexus-5K# >>>) after entering the command:
python filename.py
is because in all NX-OS versions AFTER 7.0 you must run saved python scripts via the "source" keyword and the "python" keyword is only used for entering the python interactive mode, therefore any use of "python" in version 7 and beyond will ignore a filename argument and take you directly to the interactive console.
--------------
If running the "source filename.py" command does not work, you may want to verify several things including:
(1) Verify the version of software you are running with the command "show version" (it sounds like you are running 7.0.5 due to "python" not recognizing your file)
(2) Verify that you have indeed saved the file in bootflash memory with the command "dir bootflash" (you could further specify your search for files ending in ".py" with the command "dir bootflash: | grep .py")
(3) Check if the python file you are running requires any input arguments. If it does, then running it without them may cause an error. For example, if the python script "filename.py" required an argument of a name (we'll say "Bill"), then you would want to run the command "source filename.py Bill", not just "source filename.py". This is the same for files requiring multiple arguments, eg. "source filename.py Bill Tom Samantha
----------------------
Source: Found under the "executing scripts" headline http://www.cisco.com/c/en/us/td/docs/switches/datacenter/nexus5000/sw/python/api/python_api/getting_started.html#pgfId-1053866
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide