Topic
2 replies Latest Post - ‏2013-03-07T14:43:46Z by Igs1964
Igs1964
Igs1964
18 Posts
ACCEPTED ANSWER

Pinned topic Can I embed a system variable in a batch file driven CLI statistic grab

‏2013-03-04T14:34:59Z |
Is there a way to tell CD to use the current system time minus 5 minutes when gathering stats with a ccode of 8 or 16 in a batch process? I don't see any way to set a variable time on the CLI when setting startt.

TIA,

Ian
Updated on 2013-03-07T14:43:46Z at 2013-03-07T14:43:46Z by Igs1964
  • VolkerFriedrich
    VolkerFriedrich
    132 Posts
    ACCEPTED ANSWER

    Re: Can I embed a system variable in a batch file driven CLI statistic grab

    ‏2013-03-07T11:29:39Z  in response to Igs1964
    Hi,

    you will have to build the STARTT parameter upfront in your batch file and then pipe it into the CLI.

    Unfortunately the standard CMD shell is very limited when it comes to date/time handling. While technically possible - through parsing %DATE% and %TIME% - it requires a lot of coding to get the current time minus 5 minutes. It becomes even more tricky when you need to support different date/time formats.

    Other batch languages, like VBS or PowerShell, provide better possibilities.
    Not sure if this is helpful for you, but here is a PowerShell example:
    
    # Command line arguments 
    
    for timespan (
    
    default: 5 minutes) and ccode (
    
    default: 8) param ( [
    
    int]$timespan = 5, [
    
    int]$ccode = 8 )   # Set path to CD CLI $cdcli = 
    "C:\Sterling\Connect Direct v4.6.00\Common Utilities\Direct.exe"   # Get current time - timespan $starttime = (get-date) - (new-timespan -minutes $timespan)   # Build the CD selstat command with ccode and startt If ($ccode -eq 0) 
    { $cdcmd = 
    "sel stats" 
    } Else 
    { $cdcmd = 
    "sel stats ccode=(ge," + $ccode +
    ")" 
    } $cdcmd = $cdcmd + 
    " startt=(" + $starttime.Month + 
    "/" + $starttime.Day + 
    "/" + $starttime.Year + 
    "," + $starttime.Hour + 
    ":" + $starttime.Minute + 
    ");"   # Pipe the CD command into the CD CLI Write-Output $cdcmd | & $cdcli -x
    


    Examples:
    Show any stats with ccode >= 8 for the 5 minutes (default)
    
    powershell -file SelStat.ps1
    

    Show all stats for the last two hours
    
    powershell -file SelStat.ps1 -timespan 120 -ccode 0
    
  • Igs1964
    Igs1964
    18 Posts
    ACCEPTED ANSWER

    Re: Can I embed a system variable in a batch file driven CLI statistic grab

    ‏2013-03-07T14:43:46Z  in response to Igs1964
    Hi Volker,

    Thanks for this! I was just starting to build a PS script as a test and you replied. I actually should have gone the PS route to begin with. I'll try this out and keep you posted on results.

    Cheers,

    Ian