01-09-2020 02:31 AM
Hello,
I'm trying to clean old software packages on Cat9300 Switch during ZTP.
The command "request platform software package clean switch all" shows following confirmation prompt "Do you want to proceed? [y/n]".
I tried to use an EEM script with Action 3.0 as confirmation:
cli.configurep([
"event manager applet clean" ,
"event none maxrun 300" ,
"action 1.0 cli command \"enable\"" ,
"action 2.0 cli command \"request platform software package clean switch all\",
"action 3.0 cli command \"y\" "
])
and then cli.execute("event manager run clean")
But it is not working.
An other idea: Can I modify the prompt for which the method cli.execute is waiting?
Thanks and best regards,
Magnus
Solved! Go to Solution.
01-14-2020 06:04 AM
Hi Seb,
Thanks for your hint. I found the following variable $(SWITCHNAME), so action 2.0 looks like this:
"action 2.0 cli command \"request platform software package clean switch all\" pattern \"proceed|$(SWITCHNAME)#\" "
Finally, it works.
01-09-2020 02:46 AM
HI there,
For interactive CLI prompts use the pattern command. Try replacing action 2.0 with:
"action 2.0 cli command \"request platform software package clean switch all\" pattern \"proceed\",
cheers,
Seb.
01-09-2020 06:42 AM
Thanks, Sep. It works!
But there is one problem: If there are no old packages, the pattern is never true. (see output below)
host#request platform software package clean switch all
This operation may take several minutes...
Running command on switch 1
Cleaning up unnecessary package files
No path specified, will use booted path flash:packages.conf
Cleaning flash:
Scanning boot directory for packages ... done.
Preparing packages list to delete ...
cat9k-cc_srdriver.16.12.01.SPA.pkg
File is in use, will not delete.
cat9k-espbase.16.12.01.SPA.pkg
File is in use, will not delete.
cat9k-guestshell.16.12.01.SPA.pkg
File is in use, will not delete.
cat9k-rpbase.16.12.01.SPA.pkg
File is in use, will not delete.
cat9k-rpboot.16.12.01.SPA.pkg
File is in use, will not delete.
cat9k-sipbase.16.12.01.SPA.pkg
File is in use, will not delete.
cat9k-sipspa.16.12.01.SPA.pkg
File is in use, will not delete.
cat9k-srdriver.16.12.01.SPA.pkg
File is in use, will not delete.
cat9k-webui.16.12.01.SPA.pkg
File is in use, will not delete.
cat9k-wlc.16.12.01.SPA.pkg
File is in use, will not delete.
packages.conf
File is in use, will not delete.
done.
SUCCESS: No extra package or provisioning files found on media. Nothing to clean.
host#
Can I run a cli command only for a specified pattern? Like if pattern "proceed" then "y" else if pattern "host#" then "do nothing"?
Regards,
Magnus
01-09-2020 07:36 AM
hmmm I suppose it doesn't matter it you type 'y' in EXEC mode, so you could change the pattern to regex logical OR:
"action 2.0 cli command \"request platform software package clean switch all\" pattern \"proceed|<host_name>\",
...I am sure there is a built-in EEM variable representing hostname but I can't recall what it is. In which case you will need to substitute <host_name> on each EEM script instance.
cheers,
Seb.
01-14-2020 06:04 AM
Hi Seb,
Thanks for your hint. I found the following variable $(SWITCHNAME), so action 2.0 looks like this:
"action 2.0 cli command \"request platform software package clean switch all\" pattern \"proceed|$(SWITCHNAME)#\" "
Finally, it works.
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