Hi,
I'm new here and I have no experience with programming.
I'm trying to create my first script to be used with switch/routers.
This script should connect to the device (router/switch), ping an IP address and depending on the result/reply, it execute a command.
Example:
> If ping fails (100% packet loss) = execute command "Y" (in the script, it sends a command to "reset slot 5").
> If ping is successful (0% packet loss) = execute command "X" and exit.
For now, I tried this script below. It worked when the ping fails. When the string "100% packet loss" is matched, it executes the reset.
I suppose I have to make a IF/THEN condition to first to check the ping result and then it decides to run command X or command Y. How can I implement that?
Code:
#$language = "VBScript"
#$interface = "1.0"
crt.Screen.Synchronous = True
Sub Main
crt.Screen.WaitForString "name:"
crt.Screen.Send "username" & vbcr
crt.Screen.WaitForString "password:"
crt.Screen.Send "password" & vbcr
crt.Screen.WaitForString ">"
crt.Screen.Send "enable" & vbcr
crt.Screen.WaitForString "#"
crt.Screen.Send "show date" & vbcr
crt.Screen.WaitForString "#"
crt.Screen.Send "ping 10.0.0.1" & vbcr
crt.Screen.WaitForString "100% packet loss"
crt.Screen.WaitForString "#"
crt.Screen.Send "reset slot 5" & vbcr
crt.Screen.WaitForString "confirm (y) or (n)"
crt.Screen.Send "y" & vbcr
crt.Screen.WaitForString "#"
crt.Screen.Send "show date" & vbcr
End Sub
My SecureCRT is version 8.7.0
Thanks