5 Replies Latest reply: Aug 19, 2013 9:47 AM by Dudley Credeur RSS

Custom Action Capture Buffer in Loops

Dudley Credeur

I have a custom action intended to dynamically loop thru the directory systems of a device and delete unused IOS bin files.  The steps of the action are:

 

1. Check config for image name in 'boot system' statement and save to a variable

1. Run 'show file systems' and capture directories using capture buffer. 

2. The first loop then steps thru the directories executing 'show loopvar*bin', capturing the bin filenames with a capture buffer

3. The second loop steps thru the image files found in the directory, checks if the file name found matches the current boot image.  If not, delete the image.

 

The custom action works for the most part.  The only issue is that the capture buffer of the second loop doesn't get cleared between interations.  So it may delete 4 files from the first directory.  If the second directory in the loop has no files, it will try to delete the 4 files from the first interation.  Or if the second directory has 2 files to be deleted, it will delete those two new files then attempt to delete the last two files of the first interation.  Here's an example:

 

SWITCH#dir bootflash:*bin
Directory of bootflash:/*bin

 

    2  -rwx    17500968  Dec 22 2010 08:40:53 -06:00  cat4500-entservicesk9-mz.122-50.SG8.bin
   52  -rw-       28296  Jun 15 2012 09:59:19 -05:00  img1.bin
   53  -rw-       28296  Jun 15 2012 09:59:26 -05:00  img2.bin
   54  -rw-       28296  Jun 15 2012 09:59:33 -05:00  img3.bin


61341696 bytes total (42495612 bytes free)
SWITCH#delete bootflash:img1.bin
Delete filename [img1.bin]?
Delete bootflash:img1.bin? [confirm]

 

SWITCH#delete bootflash:img2.bin
Delete filename [img2.bin]?
Delete bootflash:img2.bin? [confirm]

 

SWITCH#delete bootflash:img3.bin
Delete filename [img3.bin]?
Delete bootflash:img3.bin? [confirm]

 

SWITCH#dir slot0:*bin
Directory of slot0:/*bin

 

    9  -rw-       28296  Jun 13 2012 16:54:30 -05:00  djc.bin
   10  -rw-       28296  Jun 15 2012 10:00:18 -05:00  img4.bin


128057344 bytes total (68133840 bytes free)
SWITCH#delete slot0:djc.bin
Delete filename [djc.bin]?
Delete slot0:djc.bin? [confirm]

 

SWITCH#delete slot0:img4.bin
Delete filename [img4.bin]?
Delete slot0:img4.bin? [confirm]

 

SWITCH#delete slot0:img2.bin
Delete filename [img2.bin]?
Delete slot0:img2.bin? [confirm]

 

%Error deleting slot0:img2.bin (File not found)
SWITCH#delete slot0:img3.bin
Delete filename [img3.bin]?
Delete slot0:img3.bin? [confirm]

 

%Error deleting slot0:img3.bin (File not found)
SWITCH#dir system:*bin
Directory of system:/*bin

 

No such file

 

How can I ensure the capture buffer is cleared between each loop?