Kaseya Community

time and date in scripts

  • If i want to use the time and date in a script do i have to execute a shell command and use "time /t >>file.txt" then pull that in to a variable, or is there a kaseya variable for the current time ?

    Olly

    Legacy Forum Name: time and date in scripts,
    Legacy Posted By Username: oliverm
  • Hi Oliver,

    From what I have seen it is required to run a script to gather the date and time from a file as you have mentioned. There is good script to do so listed in this post here



    http://community.kaseya.com/xsp/f/28/t/5986.aspx



    which is this one below:



    Script Name: Check Time

    Script Description:



    IF True

    THEN

    Execute Shell Command

    Parameter 1 : time /t >> #vAgentConfiguration.agentTempDir#\time.txt

    Parameter 2 : 0

    OS Type : 0

    Get Variable

    Parameter 1 : 1

    Parameter 2 : #vAgentConfiguration.agentTempDir#\time.txt

    Parameter 3 : time

    OS Type : 0

    Write Script Log Entry

    Parameter 1 : Time at #vAgentConfiguration.Machine_GroupID# is #time#

    OS Type : 0

    ELSE


    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: djennings
  • I realize this is old, but just wanted to share what we do. We use the #vAgentConfiguration.lastCheckin# variable to timestamp items. It's not accurate to the current second, but if an agent is running a script it probably checked in within the past few minutes, so the timestamp is more or less accurate.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: arobar
  • That's not a bad idea arobar. Most of the time we are using date and time to uniquely name files and since you wouldn't be able to run a script twice in the same check in period (I believe?) then it would save a few extra steps.

    Thanks!

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: jeremyj
  • I've been using the following in a script file to get date-time stamps

    REM Calc Date-Time Stamp
    if "%date%A" LSS "A" (set toks=1-3) else (set toks=2-4)
    for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo.^|date') do (
    for /f "tokens=%toks% delims=.-/ " %%d in ('date/t') do (
    set %%a=%%d
    set %%b=%%e
    set %%c=%%f)
    )
    ::Get_Time - allways gives HH - 24hr
    for /f "tokens=5-8 delims=:., " %%a in ('echo.^|time') do (
    set hh=%%a
    set mn=%%b
    set ss=%%c
    set ds=%%d
    )
    if %hh% LSS 10 set hh=0%hh%
    REM Calc of Date-Time stamp done, below we apply it...

    echo Date-Time stamp: yyyy-mm-dd-hh-mn-ss-ds
    echo Date-Time stamp: %yy%-%mm%-%dd%-%hh%-%mn%-%ss%-%ds%
    echo Date-Time stamp: yyyy-mm-dd-hh-mn-ss-ds >> sample.log
    echo Date-Time stamp: >> sample.log
    echo Date-Time key yyyy-mm-dd-hh-mn-ss-ds >> ACT!_Backup_last_run.log
    echo Last run at: %yy%-%mm%-%dd%-%hh%-%mn%-%ss%-%ds% >> ACT!_Backup_last_run.log
    Echo Applying Date-Time stamp to .zip file
    ren sample.zip sample-%yy%-%mm%-%dd%-%hh%-%mn%.zip

    Hope that helps some.
    Ben.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: benhamilton