mIRC Need to determine if 25 hours have passed since last script execution - mirc

Basically I have this script so far:
on 1:TEXT:*some text*:#:{
if(($time(hh)-25) > $lasttime ) {
This code gets executed only once per 25 hours
$lasttime = $time(hh)
}
}
I'm not sure if I'm doing this correctly but if I am I need to know how to set $lasttime if its not already set, and if there is anyway to keep $lasttime set when mirc is closed and re opened?

Sure, save the last time it was said in a permanent variable (set %last_time ...) and check against that the next time. global mIRC %variables are kept even after close/reopen.

Related

PowerShell timing loop doesn't complete, hangs at random spot

I've created a very simple function in a powershell module which should capture a keystroke if a key is pressed within a short time window.
function get-mycommand{
$count=0
$sleepTimer=2 #in milliseconds
while ($count -le 100)
{
if($host.UI.RawUI.KeyAvailable) {
$key = $host.UI.RawUI.ReadKey('NoEcho, IncludeKeyDown')
return $key.character
} else {
$count++
Write-Host $count
Start-Sleep -m $sleepTimer
}
}
return "fail"
}
function test-get-command{
$myvalue = get-mycommand
Write-Host 'return ' $myvalue
}
This works fine so long as I press a key quickly. If I don't press a key then it will count up to some random number, usually less than 20, and then stop updating. It won't do anything until I press a key and it never times out. When I do press a key, even after several minutes it will return with the character. I never see the 'fail' message at all.
Using a longer timer interval doesn't change anything.I've tried a sleeptimer of 2, 20 & 200. They all behave the same.
Unfortunately, $host.UI.RawUI.KeyAvailable can have false positives in Windows PowerShell as well as in PowerShell (Core) up to at least v7.2.0-preview.9 (current as of this writing).
On Windows, it seemingly thinks a key is available even when there isn't, so that $key = $host.UI.RawUI.ReadKey('NoEcho, IncludeKeyDown') is executed, which indefinitely waits for an actual keypress.
In a regular console window this seems to happen after a few iterations at the latest.
In Windows Terminal, it seems to happen consistently on the first iteration, so that your function produces no output at all.
GitHub issue #959 seems relevant, although it relates to the PSReadLine module.
While unloading the module (Remove-Module PSReadLine) - which you wouldn't want to do in a interactive session - does fix the problem in regular console windows, it doesn't help in Windows Terminal.
Workaround:
Replace $host.UI.RawUI.KeyAvailable with [Console]::KeyAvailable
Note that this limits use to consoles (terminals), but your original code wouldn't work in the obsolescent ISE anyway, because $host.UI.RawUI.KeyAvailable there seemingly never reports a pending keypress.

How to stop after each command

I have a high impact script and I want to confirm each command. The script calls several other scripts.
So it looks like this
stop_db
migrate_db
..
update_app
..
If I set $ConfirmPreference = 'low' I must confirm everything inside the above procedures as well. Is it possible to confirm actions only from the top script the easy way ?
EDIT: Ideally, this should be as simple as:
Enable-BreakAfterEach
stop_db #stop here with continue y/n but not inside
migrate_db #""
..
update_app
..

Processing a list with Powershell on a Scheduled Task

I'm a newbie to powershell, so I'm not sure if I am over thinking what I want to do, hopefully somebody can help me out.
I want to create a Windows scheduled task that calls my powershell script every 4 hours, no problems there. The script needs to process a list of ID's that range from 1 to 140,(They skip a few here and there which makes this harder) the script is just calling another external program that takes about 2 hours per ID, we give it 4 hours to be safe. So upon the powershell script loading, it needs to read from a file the last scan it did, I can do that using
$lastscan = Get-Content'lastScan.txt'
Then the script needs to find the next object in the list, which may skip a number here or there so it's not as simple as just incrementing the last scan run. Once it has the next ID it will kick off the scan and save the new value to the text file named "lastScan.txt" and exit. The only thing I need help with, is how to find the next scan in my list based on the lastscan run. The list is seperated by newline, but I could edit it if it makes it easier.
1
5
6
9
etc, etc, ...
Assuming you have a string array that was populated with Get-Content and assuming the array did not contain duplicates, you could use the Array.IndexOf method to get the index of the current id and then return the next element in the array. Example:
$x = "1","2","3"
$currentId = "2"
$nextIndex = [array]::IndexOf($x, "2") + 1
$nextId = $x[$nextIndex] #nextId should now be "3"

How to search for a particular string and goto sleep if not found in perl?

I have two test cases in log file ActivateJob and GetJOBStatus as below, my perl script currently set to PASS as default and it searches for Error in the below test cases, if it finds error in the below it makes test case as FAIL. For GetJOBStatus test case if it is ACTIVE script as to sleep for couple of mins and it as to perform GetJOBStatus again and if it is success test case as to be passed or else fail. How can i perform sleep and search for active in GetJOBStatus test case.. ply help me out... thanks in advance..
==============log file===================
Date and Time is:Thu, 20-06-2013 06:04:19
Line 4 Command:ActivateJob(Job=Test_Abort_New1);
Answer:
ActivateFTSJobResult = Success
COMPLETED
Date and Time is:Thu, 20-06-2013 06:04:19
Line 5 Command:GetJOBStatus(Job=Test_Abort_New1);
Answer:
GetJOBStatusResult = NELabel,Status,ErrorReason,Progress,CurrentUnit,Total
TSS_320_1,ACTIVE,No Error,0,BACKUP.DSC,0
COMPLETED
In order to check for a string in a file, you have to
open the file using open
read the file using <>
search the file using m//
close the file
In order to sleep (for a seconds), you have to sleep(a)
Keep in mind that unless you perform seek on your filehandle, you will have to close and then re-open it in order for it to reach the beginning.
As for you specific question, it appears to be implemented as an example in the seek perldoc

AutoHotKey: iniwrite then read of formattime not the same as result of formattime

Here's my code:
IniRead, intLastMyDate, c:\temp\test.ini, section1, intLastMyDate, 130101
formattime, intCurrentMyDate, A_Now, yyMMdd
; if the ini has a date stored that is less than today, I will want to
; include code that restarts some other variables for a new day
; but if the date is the same as today, I want to leave those values alone,
; no matter how many times I reload the script after fiddling with the code
if intLastMyDate < intCurrentMyDate
{
IniWrite, %intCurrentMyDate%, c:\temp\test.ini, section1, intLastMyDate
; following just to show failure of test to do what I expect
MsgBox, if condition evals %intLastMyDate% < %intCurrentMyDate% as true
}
The first time I load the script, it results as expected. When I reload it, it seems to be thinking that 130510 (the day I posted this) is less than 130510. Is this a data type problem? The help says that anything that looks like a number evals as a number ...
Change one line:
if (intLastMyDate < intCurrentMyDate)