Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > General

Reply
 
Thread Tools Display Modes
  #1  
Old 09-16-2020, 02:05 PM
sussington sussington is offline
Registered User
 
Join Date: Sep 2020
Posts: 6
Time and Date Function

I am not sure if this is a possibility or not.

Is there a way to program a button to send a string that includes a current date and/or time command in any format that I choose.

For example: I have several Adtran cabinets that cannot do domain-lookup so they are not able to look at an NTP server for their time reference. The time has to be set manually.

So I would like to program a button that tells the terminal to go into configure termal, then clock set (current time in HH:MM:SS format) then hits enter instead of having to manually type it all in.

Then also have something similar to setting the date as well.
Reply With Quote
  #2  
Old 09-16-2020, 02:32 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,448
Hi sussington,

What version of SecureCRT?

On what OS/platform?

Please list the explicit steps you would take to perform the action manually.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 09-16-2020, 02:48 PM
sussington sussington is offline
Registered User
 
Join Date: Sep 2020
Posts: 6
Brenda,

Thank you for responding.

I am using version 8.7.3 of SecureCRT (I believe this is the latest) on a Windows 10 PC.

The exact set of commands after logging into the terminal and enabling priviliage mode is as followed:

conf t (carriage return)
clock set <HH:MM:SS> <DD Mmm YYYY>(without the "<>")(carriage return)

and that is it. HH is in 24 hour format.

Here is an example of the full command:

conf t
clock set 15:47:26 16 Sep 2020

Last edited by sussington; 09-16-2020 at 02:56 PM.
Reply With Quote
  #4  
Old 09-16-2020, 03:06 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,448
Hi sussinsgton,

So are you saying when you press <ENTER> that it supplies current time and date? Or do you have to supply it?

Assuming the former, just set the Function for the button to be Send String and then below is the string you would use.

conf t\r
clock set HH:MM:SS DD Mmm YYYY\r

See also these two videos:

- Button Bar Video
https://www.youtube.com/watch?v=olyCcUWRimI

- Button Bar Enhancements in SecureCRT
https://youtu.be/qp82UWxGB8I
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 09-16-2020, 03:50 PM
sussington sussington is offline
Registered User
 
Join Date: Sep 2020
Posts: 6
Brenda,

It is the latter of the two. I have to provide the the information for HH:MM:SS DD Mmm YYYY

I was wonding if there is a way I can have SecureCRT gather that information automaically from the OS or and NTP (for example)and then I can set that information in a command format via a button.
Reply With Quote
  #6  
Old 09-16-2020, 03:56 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,448
Hi sussington,

That's the info I was looking for as well. At that point, you would probably need to run a script so you can add some logic to capture that info.

I am not familiar with Adtran devices. Is there a Date() or Now() function provided by the shell?

Would you connect with trace options output (enabled from the File menu) and then post the line (about 5-10 lines from top) that includes the Remote Identifier?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #7  
Old 09-16-2020, 05:58 PM
kdmorse kdmorse is offline
Registered User
 
Join Date: Feb 2018
Posts: 14
Quote:
Originally Posted by sussington View Post
I was wonding if there is a way I can have SecureCRT gather that information automaically from the OS or and NTP (for example)and then I can set that information in a command format via a button.
I had a script lying around that essentially does just that, and you can bind it to a button for convenience:

setclock.py

Code:
# $language = "Python"
# $interface = "1.0"

from datetime import datetime

def Main():

    CRT = crt
    Screen = CRT.Screen
    Screen.Send("config term\r")

    Now = datetime.now()
    Formatted = Now.strftime("%H:%M:%S %d %b %Y")
    Screen.Send("clock set " + Formatted + "\r")

Main()
Example:

Code:
MDS9710# config term
Enter configuration commands, one per line.  End with CNTL/Z.
MDS9710(config)# clock set 19:55:37 16 Sep 2020
Wed Sep 16 19:55:37 EDT 2020
MDS9710(config)#
The code should be straightforward enough that you can adjust it to taste with minimal effort.
Reply With Quote
  #8  
Old 09-17-2020, 07:17 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,448
Hello,

Thanks kdmorse!

Sussington,

Are you able to incorporate kdmorse's suggestions and then map a button on the button bar to run the script?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #9  
Old 09-17-2020, 07:45 AM
sussington sussington is offline
Registered User
 
Join Date: Sep 2020
Posts: 6
Thanks kdmorse and bgagnon I really appreciate the replys. I'm not to family as to how scripting works and will need to do some research how to go about adding this in and how it works.
Reply With Quote
  #10  
Old 09-17-2020, 08:16 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,448
Hi sussington,

The only thing different is what you said your initial command sent needs to be.

So it would look something like below. Note that you need to put in whatever your shell prompt is where noted:

Code:
# $language = "Python"
# $interface = "1.0"

from datetime import datetime

def Main():
    
    CRT = crt
    Screen = CRT.Screen
    Screen.Synchronous = True
    Screen.Send("config t\r")
    Screen.WaitForString("your_shell_prompt")

    Now = datetime.now()
    Formatted = Now.strftime("%H:%M:%S %d %b %Y")
    Screen.Send("clock set " + Formatted + "\r")

Main()
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #11  
Old 09-17-2020, 11:41 AM
kdmorse kdmorse is offline
Registered User
 
Join Date: Feb 2018
Posts: 14
Quote:
Originally Posted by sussington View Post
Thanks kdmorse and bgagnon I really appreciate the replys. I'm not to family as to how scripting works and will need to do some research how to go about adding this in and how it works.
Very short version:

Create an empty file named setclock.py, and paste one of the scripts into it, and save it somewhere on your hard disk. (make sure it's named setclock.py, not setclock.py,txt). Then as a test, on the menu hit Script -> Run Script, navigate to your script, and hit run.

If it suits your needs, you can then add a button, or command manager line, (or even keybind) that maps to Run Script -> yourscript name.
Reply With Quote
Reply


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

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 02:05 PM.