Jump to content
Sign in to follow this  
sammy1983

Error finding

Recommended Posts

sammy1983

Hi,

Need clarification. If I run a script to perform a repetitive task in Hidden/Invisible mode, how will I know if the script is still running without any problem or if the script has stopped/failed in between? Is there a way that I will be informed via Outlook mail or via Toast message or using msgbox?

Share this post


Link to post
Share on other sites
orbs

there are several ways:

1) by exit code:

if a script crashed, or killed by Task Manager, a typical exit code is 1. you can use that depending on how you launch your script. for example, if it's by another script, then that script can set an alarm if exit code is 1 (or other than zero). that's the closest you can get to passive monitoring.

2) by active monitor - main script presence:

set another script to run constantly in the background, hooked to the processes list. if it detects an event that the main script is gone from the processes list, it can set an alarm.

3) by active monitor - main script log/flag:

have the main script log it's activity, or raise a flag ("touch" a file) every few seconds. set a monitoring script to check the "modify" timestamp of the log file or flag, and set an alarm if it's older than those few seconds (or 2x few seconds, to be safe).

4) by pending alarm:

create a scheduled task that will alarm you in 2x few seconds. have your script re-schedule that scheduled task every few seconds. so if the script fails, the alarm will not be re-scheduled and will fire in 2x few seconds.

my favorite method is (1), but that depends on the specific situation.

Share this post


Link to post
Share on other sites
sammy1983

there are several ways:

1) by exit code:

if a script crashed, or killed by Task Manager, a typical exit code is 1. you can use that depending on how you launch your script. for example, if it's by another script, then that script can set an alarm if exit code is 1 (or other than zero). that's the closest you can get to passive monitoring.

2) by active monitor - main script presence:

set another script to run constantly in the background, hooked to the processes list. if it detects an event that the main script is gone from the processes list, it can set an alarm.

3) by active monitor - main script log/flag:

have the main script log it's activity, or raise a flag ("touch" a file) every few seconds. set a monitoring script to check the "modify" timestamp of the log file or flag, and set an alarm if it's older than those few seconds (or 2x few seconds, to be safe).

4) by pending alarm:

create a scheduled task that will alarm you in 2x few seconds. have your script re-schedule that scheduled task every few seconds. so if the script fails, the alarm will not be re-scheduled and will fire in 2x few seconds.

my favorite method is (1), but that depends on the specific situation.

 

Thanks Orbs. Method (1) would be more appropriate. How to achieve this? Can you show the code part? Thanks.

Share this post


Link to post
Share on other sites
orbs

as i said, that depends on how you launch your script. so, how do you launch your script?

Share this post


Link to post
Share on other sites
sammy1983

as i said, that depends on how you launch your script. so, how do you launch your script?

 

I have made an exe file and upon double clicking the script runs. Is that what u asked or have I misunderstood your question?

Share this post


Link to post
Share on other sites
orbs

yes, that's what i mean. but in this case, if the script crash, it will report the exit code of 1 to the Windows shell (explorer.exe). you can not program explorer.exe to handle it - at least not without additional scripting, which is basically what methods (2) and (3) do.

Share this post


Link to post
Share on other sites
sammy1983

yes, that's what i mean. but in this case, if the script crash, it will report the exit code of 1 to the Windows shell (explorer.exe). you can not program explorer.exe to handle it - at least not without additional scripting, which is basically what methods (2) and (3) do.

 

Can you show the way to perform this using method (2)?

Share this post


Link to post
Share on other sites
orbs

try here:

'?do=embed' frameborder='0' data-embedContent>>

the "Best Answer" code works as is. it is configured to write to console every event of a process start or end. you can customize it for specific process and fire any alarm.

Share this post


Link to post
Share on other sites
sammy1983

Hi Orbs.. I found the "Best Answer" to be apt, however I was wondering how can I integrate this in my script? or do I have to run a parallel script along with mine so that it can detect when that process is ending from explore.exe? Any suggestions?

Share this post


Link to post
Share on other sites
orbs

you have to run it as an independent parallel script, because if the main script crash, then its own monitoring capability is also crashed.

Share this post


Link to post
Share on other sites
sammy1983

you have to run it as an independent parallel script, because if the main script crash, then its own monitoring capability is also crashed.

 

Yup. I guessed so. So if I run the main script, it should trigger this parallel script as well to monitor the process change, right?

Share this post


Link to post
Share on other sites
orbs

up to you. you can either have the main script launch the monitoring script before it starts, but then if it crash and you re-launch it, make sure you do not have the monitoring script re-launched too, because the monitoring script itself did not crash, or have the monitoring script automatically launched at startup.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×