This example script deletes a read only community string from the selected Cisco device. It relies on the task that is calling the script having an oldCommunity parameter. Different tasks can use the same remove community string step but have different values for their oldCommunity parameter.
1. expect.with
2. {
3. if( vendor.equals("9") )
4. {
5. sendln "configure terminal"
6. expect( configPrompt, {} )
7. setDiagnosticLogging false
8. setLogUser false
9. sendln "no snmp-server community " + param.oldCommunity + " ro"
10. expect( configPrompt, {} )
11. setLogUser true
12. setDiagnosticLogging true
13. }
14. else
15. {
16. println "NO VALID METHOD FOR THIS DEVICE"
17. throw new Exception("no valid method for this device")
18. }
19. }
Overview of the remove read only community string script structure:
- Line 3. finds the seventh character of the sysOID to identify the device vendor.
- Line 5. sets the terminal to configure.
- Lines 7. and 8. turn off the terminal logging. This hides the community string from the
display. - Line 9. removes the snmp-server community string that matches the value of the task’s oldCommunity parameter.
- Line 10. checks for the return of the prompt. This instruction is sent before turning on logging as it clears from the expect buffer the community string. The next two lines turn on logging and will clear the buffer and in doing so display the prompt.
- Lines 11. and 12. turn on the terminal logging.
- Line 14. to Line 18. return an error message when the device is not a Cisco device.
Comments
0 comments
Please sign in to leave a comment.