Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-12-2007, 02:51 PM
jujordan jujordan is offline
Registered User
 
Join Date: Sep 2007
Posts: 23
Trying to get Secure CRT to run with Windows Task scheduler

When I try to run this in task scheduler, i get a hostname lookup failed. Below is my string that I put in the run box of task scheduler, does anyone know how I can automate this to run at scheduled times? I can get Secure CRT to open with this part of the line (C:\PROGRA~1\SECURE~1\SECURE~1.EXE), but it wont run the script with this part of the line /script "C:\Program Files\SecureCRT\scripts\Omaha NAV.vbs"). Anyone have any ideas?



C:\PROGRA~1\SECURE~1\SECURE~1.EXE" /script "C:\Program Files\SecureCRT\scripts\Omaha NAV.vbs"
  #2  
Old 09-12-2007, 03:25 PM
wakti wakti is offline
Registered User
 
Join Date: Jan 2007
Posts: 10
Create a session with this script configured and then generate a shortcut to the desktop. In your task, link to the shortcut.
  #3  
Old 09-12-2007, 03:30 PM
jujordan jujordan is offline
Registered User
 
Join Date: Sep 2007
Posts: 23
Secure CRT

Create a session with this script configured and then generate a shortcut to the desktop......not sure I understand what you mean
  #4  
Old 09-12-2007, 03:34 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Quote:
C:\PROGRA~1\SECURE~1\SECURE~1.EXE" /script "C:\Program Files\SecureCRT\scripts\Omaha NAV.vbs"
It looks like there's a missing quotation mark.
C:\PROGRA~1\SECURE~1\SECURE~1.EXE"
should be:
"C:\PROGRA~1\SECURE~1\SECURE~1.EXE"
As far as the hostname lookup failure, it sounds like the script is running, so I'm not sure that the missing quotation mark is anything more than a forum post typo. Based on our other forum conversations I think it's possible that %computername% is only defined for a particular user and perhaps is not defined when running as a scheduled task.

Who is the task scheduled to run as in task scheduler?

Since your computername isn't changing, could you just use your computer's actual hostname instead of depending on variable expansion of %computername%?
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
  #5  
Old 09-12-2007, 05:18 PM
jujordan jujordan is offline
Registered User
 
Join Date: Sep 2007
Posts: 23
reply

Yes the script is running, however it does not telnet to the device according to the script. for instance the tab in secure CRT shows the IP of the host that I am telnetting to. This works as it should when I open a Secure CRT session, choose script and then choose the scipt with the name Omaha NAV.vbs. However when I do the task sheduler, everything works as designed but when the script starts to run, instead of showing the IP of the host on the tab, it shows then name of the script and then i get a hostname failure. Kinda odd.
  #6  
Old 09-13-2007, 10:17 AM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
It sounds like there's a subtle error that may only be solved by reading the script.

Can you post the script and the command you're running in task scheduler?

If you run the script manually rather than via the task scheduler does it work correctly?
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
  #7  
Old 09-13-2007, 10:40 AM
jujordan jujordan is offline
Registered User
 
Join Date: Sep 2007
Posts: 23
Mike

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

'Code:
'~ If running this script outside of SecureCRT, uncomment the following lines
'Set g_Shell = WScript.CreateObject("WScript.Shell")
'Main

'~ If running this script from within SecureCRT, uncomment the following line
Set g_Shell = CreateObject("WScript.Shell")


Dim navuser
Dim navpswd
Dim navsite
Dim addr
Dim szIPaddr

navuser="XXX"
navpswd="XXX"

Sub Main

IPaddress = g_Shell.Run("cmd /c ipconfig")

strCmdString = "ping -n 1 -w 100 %computername%"

set objWshShell = CreateObject("WScript.Shell")

set objExec = objWshShell.Exec(strCmdString)

do while not objExec.StdOut.AtEndOfStream
szOutput = szOutput & objExec.StdOut.Readline()
loop

szIPaddr = ParseIPfromPing(szOutput)

If szIPaddr = "" Then
MsgBox "Unable to find IP address from ping output"
Exit Sub

End If

navsite="""XXX"""
addr="10.x.x.x."
call work (navuser, navpswd, navsite, addr, szIPaddr)

navsite="""XXX"""
addr="10.x.x.x"
call work (navuser, navpswd, navsite, addr, szIPaddr)

navsite="""XXX"""
addr="10.x.x.x"
call work (navuser, navpswd, navsite, addr, szIPaddr)

navsite="""XXX"""
addr="10.x.x.x"
call work (navuser, navpswd, navsite, addr, szIPaddr)

navsite="""XXX"""
addr="10.x.x.x
call work (navuser, navpswd, navsite, addr, szIPaddr)

navsite="""XXX"""
addr="10.x.x.x"
call work (navuser, navpswd, navsite, addr, szIPaddr)

navsite="""XXX"""
addr="10.x.x.x"
call work (navuser, navpswd, navsite, addr, szIPaddr)


End Sub

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~ ParseIPfromPing
'~ Parses output from the following command:
'~ ping %computername% -n 1 -w 100
'~ Pinging machine.domain.org [10.1.1.102] with 32 bytes of data:
'~ ...

Function ParseIPfromPing(strng)
Dim regEx, Match, Matches ' Create variable.
Set regEx = New RegExp ' Create regular expression.
regEx.Pattern = "\[(.*)\]" ' Set pattern.
regEx.IgnoreCase = False ' Set case insensitivity.
regEx.Global = True ' Set global applicability.

If Not regEx.Test(strng) Then
Exit Function
End If

Set Matches = regEx.Execute(strng) ' Execute search.

For Each Match in Matches
ParseIPfromPing = Match.Submatches(0)
Exit Function
Next

End Function

Sub work (navuser, navpswd, navsite, addr, szIPaddr)

crt.Session.Connect "/TELNET " & addr
crt.sleep 1000
crt.Screen.Send vbCr
crt.Screen.WaitForString "Login: "
crt.Screen.Send navuser & vbCr
crt.Screen.WaitForString ">"
crt.Screen.Send "upload tftp config " & szIPaddr & navsite & vbCr
crt.Screen.WaitForString ">"
crt.Screen.Send "exit" & vbCr
crt.sleep 1000

End Sub



C:\PROGRA~1\SECURE~1\SecureCRT.EXE /script C:\Program" Files\SecureCRT\scripts\NA NAV backups.vbs"
  #8  
Old 09-13-2007, 11:03 AM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Quote:
it does not telnet to the device according to the script.
This is the line that specifies where to telnet to. CRT is telnet'ing to the addr that you pass in:
crt.Session.Connect "/TELNET " & addr
I'm still not sure I understand the process that's supposed to occur. Do you need to telnet to the device or to the server?

There is another quoting problem but I'm not sure if this is a typo you made when typing your forum post or if this is how you actually enterred the task in Windows Task Scheduler:
Quote:
C:\PROGRA~1\SECURE~1\SecureCRT.EXE /script C:\Program" Files\SecureCRT\scripts\NA NAV backups.vbs"
The quote should start before C:\Program Files, not in the middle of C:\Program" Files:
C:\PROGRA~1\SECURE~1\SecureCRT.EXE /script "C:\Program Files\SecureCRT\scripts\NA NAV backups.vbs"
Quote:
when I do the task sheduler, everything works as designed but when the script starts to run, instead of showing the IP of the host on the tab, it shows then name of the script and then i get a hostname failure
It's very odd - and I cannot duplicate the problem. It doesn't sound like the script is working correctly when you run it in Windows Task Scheduler. I ran this simple script and the tab shows the name of the host I telnet to:
Code:
Crt.Session.Connect " /Telnet " & "192.168.0.123"
Crt.Screen.WaitForString "login: ", 60
Crt.Screen.Send "miked" & vbcr
MsgBox "hello world"
Here is how I ran the script:
securecrt /script c:\scripts\simple_hello.vbs
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
  #9  
Old 09-13-2007, 12:36 PM
jujordan jujordan is offline
Registered User
 
Join Date: Sep 2007
Posts: 23
Mike

Thanks I got it working, i needed to add /script. Thanks for all the help. PS, I will be on a cruise next week so you will not have to deal with me again.
  #10  
Old 09-13-2007, 02:26 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Thanks for the update - I'm glad to hear you got it working!
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 10:22 AM.