PDA

View Full Version : Run Command - Email Results Hourly


bccsrc
07-20-2009, 05:39 PM
I need some help. I would like to create a script to run every hour by itself using Windows Task Scheduler ??? then send the results to me via email.

Here is what I have so far:

Start Script:

#$language = "VBScript"
#$interface = "1.0"

Sub Main

' I will need to add the commands to login to the blade with the username and password here.

For i = 0 To 3600000

'Test script every 5 seconds
crt.sleep 5000

Dim result
crt.Screen.Send "show environment temperatures" & chr(13)
crt.Screen.WaitForString "#"
result = crt.screen.ReadString '(Is this correct?)

Set objMessage = CreateObject("CDO.Message")

Set objConf = CreateObject("CDO.Configuration")

Set objFlds = objConf.Fields
With objFlds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "my mail server"
.Update
End With

With objMessage
Set .Configuration = objConf
.To = "my email address"
.From = "my email address"
.Subject = result
.TextBody= " "
.Send
End With

Next



End Sub

End Script

Here is the actual command I run:

XXXX6252_R5_s1#show environment temperatures
Temperatures: External temperature 46 C
Internal temperature 54 C
#2 External temperature Mezz1 46 C
#1 External temperature Mezz1 54 C
Internal temperature Mezz1 50 C
XXXX6252_R5_s1#

Thank you!!

Brandon

rtb
07-21-2009, 11:13 AM
Hi Brandon,

It looks like you are really close to having a working script.

I would suggest replacing crt.Screen.WaitForString "#" with crt.Screen.ReadString "#"

We also have a scripting manual that illustrates scripting in SecureCRT posted at the following location:
http://www.vandyke.com/support/tips/scripting/index.html
Chapter 3 specifically covers connecting to remote machines.

Another option to code the connection is to start the Script Recorder (Script / Start Recording Script) prior to logging into a machine, and then go through your process manually. This will create a script of your manual process.

Does this information help you finish writing your script?

If not, are you encountering a specific problem or error?

bccsrc
07-21-2009, 01:03 PM
I still have something wrong. I am not sure how to get the results of the crt.screen.ReadString.

#$language = "VBScript"
#$interface = "1.0"

' This automatically generated script may need to be
' edited in order to work correctly.

Sub Main

Dim result
crt.Screen.WaitForString "Password: "
crt.Screen.Send "my password" & chr(13)
crt.Screen.WaitForString ">"
crt.Screen.Send "en" & chr(13)
crt.Screen.WaitForString "Password: "
crt.Screen.Send "my password" & chr(13)
crt.Screen.WaitForString "#"
crt.Screen.Send "show ver" & chr(13)
crt.Screen.WaitForString "MTAS6252_R5_s1#"
crt.Screen.Send "show env" & chr(9) & "temp" & chr(9) & chr(13)
crt.screen.ReadString "MTAS6252_R5_s1#"
result = crt.screen.ReadString

Set objMessage = CreateObject("CDO.Message")

Set objConf = CreateObject("CDO.Configuration")

Set objFlds = objConf.Fields
With objFlds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mymailserver"
.Update
End With

With objMessage
Set .Configuration = objConf
.To = "my email address"
.From = "my email address"
.Subject = result
.TextBody= " "
.Send
End With

'Next



End Sub

rtb
07-21-2009, 03:46 PM
Hi Brandon,

I apologize for the mis-understanding.

I meant to say that you must assign crt.Screen.ReadString("MTAS6252_R5_s1#") to a variable.

For example:
result = crt.Screen.ReadString("MTAS6252_R5_s1#")

You would also need to remove result = crt.screen.ReadString.

Does this help you get your script working?

bccsrc
07-21-2009, 04:01 PM
Awesome! It is working.

Now how do I set it up to run using Windows Task Scheduler?

Thanks,

Brandon

rtb
07-22-2009, 10:39 AM
Hi Brandon,

Thanks for the update. I am glad to hear that the script is working.

The Windows Task Scheduler is outside of the support that we can offer at VanDyke Software Technical Support.

You should be able to find tutorials for using the Windows Task Scheduler by searching the internet using your favorite search engine.

I can say that you will need to create the task and point it to the .vbs file, and then open the advanced properties of the task to modify the task to run more frequently than once a day.