VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   General (https://forums.vandyke.com/forumdisplay.php?f=11)
-   -   Time and Date Function (https://forums.vandyke.com/showthread.php?t=14288)

sussington 09-16-2020 02:05 PM

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.

bgagnon 09-16-2020 02:32 PM

Hi sussington,

What version of SecureCRT?

On what OS/platform?

Please list the explicit steps you would take to perform the action manually.

sussington 09-16-2020 02:48 PM

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

bgagnon 09-16-2020 03:06 PM

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

sussington 09-16-2020 03:50 PM

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.

bgagnon 09-16-2020 03:56 PM

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?

kdmorse 09-16-2020 05:58 PM

Quote:

Originally Posted by sussington (Post 54026)
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.

bgagnon 09-17-2020 07:17 AM

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?

sussington 09-17-2020 07:45 AM

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.

bgagnon 09-17-2020 08:16 AM

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()


kdmorse 09-17-2020 11:41 AM

Quote:

Originally Posted by sussington (Post 54031)
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.


All times are GMT -6. The time now is 01:29 AM.