View previous topic :: View next topic |
Author |
Message |
Bobzbobz
Joined: 30 Nov 2010 Posts: 30 Location: Denmark
|
Posted: Tue Jun 02, 2020 5:34 am Post subject: Simple reminder test |
|
|
Hello
Is it possible to create a simple "reminder test" based on a specific date, which then alerts when X days until a date is reached.
I am using a license server to apply educational licenses to our Autodesk-products. These licenses only last 1 year and then need renewal. The licenses are specified in a .txt-file.
I would like to create a test where I can specify the renewal-date and then have it come out with "bad status" when there are 30 days left. |
|
Back to top |
|
|
KS-Soft
Joined: 03 Apr 2002 Posts: 12795 Location: USA
|
Posted: Tue Jun 02, 2020 6:18 am Post subject: |
|
|
I see several options
1) If your system date format looks like YYYY-MM-DD, you may set any test with static good result (e.g. Ping localhost) with the following option
- Use Warning status if "%Date%">"2021-05-01"
2) You may use Schell Script test method and create simple script that will check system date (e.g. VBScript, JavaScript or PowerShell)
3) Create any file, set modification timestamp to May 02, 2021, set File/Folder Availablity test using the following option
- Alert when file does not exist or older then 1 min
Option #2 is the most reliable, it will work if system date format changes, it will not fail if someone opens file in text editor and clicks File->Save
Regards
Alex |
|
Back to top |
|
|
Bobzbobz
Joined: 30 Nov 2010 Posts: 30 Location: Denmark
|
Posted: Thu Jun 04, 2020 1:03 am Post subject: |
|
|
Thank you for the quick reply
Should this work?
I get "Error: Invalid Result"
Code: | $statusAlive = "ScriptRes:Host is alive:"
$statusDead = "ScriptRes:No answer:"
$statusUnknown = "ScriptRes:Unknown:"
$statusNotResolved = "ScriptRes:Unknown host:"
$statusOk = "ScriptRes:Ok:"
$statusBad = "ScriptRes:Bad:"
$statusBadContents = "ScriptRes:Bad contents:"
$CurDate = Get-Date -Format "dd-MM-yyyy"
if ($args[0]>$CurDate)
{
echo $statusBad"$CurDate"
exit
}
else
{
echo $statusOk
exit
} |
|
|
Back to top |
|
|
KS-Soft
Joined: 03 Apr 2002 Posts: 12795 Location: USA
|
Posted: Thu Jun 04, 2020 7:08 am Post subject: |
|
|
Get-Date -Format "dd-MM-yyyy" returns a string, not a date.
(Get-Date returns date)
So if you want to compare strings then use different format
Get-Date -Format "yyyy-MM-dd"
Also, check list of comparison operators
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comparison_operators?view=powershell-7
Code: |
$statusUnknown = "ScriptRes:Unknown:"
$statusOk = "ScriptRes:Ok:"
$statusBad = "ScriptRes:Bad:"
if (!$args[0]) {
echo $statusUnknown"Date (YYYY-MM-DD) parameter is not specified"
exit
}
$CurDate = Get-Date -Format "yyyy-MM-dd"
if ($args[0] -gt $CurDate)
{
echo $statusBad"$CurDate"
}
else
{
echo $statusOk
} |
Regards
Alex |
|
Back to top |
|
|
Bobzbobz
Joined: 30 Nov 2010 Posts: 30 Location: Denmark
|
Posted: Mon Jun 08, 2020 6:15 am Post subject: |
|
|
Thank you. |
|
Back to top |
|
|
|