Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scheduling multiple CMS Reports reliably

Status
Not open for further replies.

Bucky101

IS-IT--Management
Feb 9, 2006
419
AU
I am currently using windows task scheduler to run a .bat file which then runs a single acsauto report every 2 minutes.
Because of the unreliabity of the Avaya System, the .bat starts by killing off any CMS processes that did not completely close from the previously ran schedule

I want to run the acsauto script and wait for its completion rather than sleeping for 90 seconds and hoping for the best.
Does anyone have a reliable way of doing this?

Scheduled.bat
taskkill /F /IM ACS* /T
taskkill /F /IM acs* /T
wmic process where name="ACSApp.exe" call terminate

rem Running the realtime report
start "" "C:\Avaya Reports\Realtime.acsauto"
timeout /t 90 /nobreak > NUL

powershell.exe -ExecutionPolicy RemoteSigned -File "Something-else.ps1"
 
I've rewritten your PS below, give that a try and see if it improves reliability..

Code:
# Terminate any existing ACS process
$processes = Get-Process -Name "ACSApp" -ErrorAction SilentlyContinue
if ($processes) {
    foreach ($process in $processes) {
        Stop-Process -Id $process.Id -Force
    }
}


# Run the realtime report
Start-Process "C:\Avaya Reports\Realtime.acsauto"


# Wait for the report to finish
Start-Sleep -Seconds 90


# Run the next script
& "Something-else.ps1"

Personally, I've gotten away from PowerShell and use python for every task...

Code:
import subprocess
import time
import psutil
import os

# Function to kill any existing ACS process
def kill_acs_process():
    for proc in psutil.process_iter(['pid', 'name']):
        if proc.info['name'] and "ACSApp" in proc.info['name']:
            proc.kill()

# Function to run the ACS report
def run_report():
    subprocess.Popen(["C:\\Avaya Reports\\Realtime.acsauto"])
    time.sleep(90)  # Wait for the report to finish

# Function to monitor and handle memory usage
def monitor_acs_process():
    for proc in psutil.process_iter(['pid', 'name', 'memory_percent']):
        if proc.info['name'] and "ACSApp" in proc.info['name']:
            if proc.info['memory_percent'] > 75:  # Threshold for memory usage
                proc.kill()
                return False  # Indicate that the process was killed
    return True  # Process is running fine

def main():
    while True:
        kill_acs_process()  # Ensure no existing ACS process
        run_report()  # Run the report
       
        if not monitor_acs_process():
            print("ACS process exceeded memory limits and was killed. Restarting...")
            continue  # Restart the loop to run the report again
       
        # Run the next script
        subprocess.Popen(["powershell.exe", "-ExecutionPolicy", "RemoteSigned", "-File", "Something-else.ps1"])

        time.sleep(120)  # Wait for 2 minutes before running again

if __name__ == "__main__":
    main()


You can convert the above python to a .exe and schedule it... If it's on a server or PC that is always on, you can write the schedule inside python -- let me know and I'll show you how.

Finally, is this a historical report? -- If so, you can get the data via an ODBC connection which is much more reliable than both code snippets above.
 
Last edited:
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top