ryanblenis / MeshCentral-ScriptTask

Scripting plugin for MeshCentral
Apache License 2.0
54 stars 14 forks source link

Script running forever #7

Open vish84 opened 4 years ago

vish84 commented 4 years ago

Hi Thanks for this plug-in, as this could help me in a unique requirement where I need to run a script on a machine, and just been trying to test with it.

I have uploaded a ps1 script. when I click run, it keeps running and copying the file locally, but the script never finishes.

How can I stop the task from the UI.

running multiplecopies
vish84 commented 4 years ago

I managed to stop the tasks on the machine, I found this from a comment you made on reddit plugin scripttask clearAll

However, this stops the tasks on the machine, but from the UI, node history still shows as Running. I also removed all scripts.

Appreciate this is in early development and will be issues. Thanks for the the effort.

image

vish84 commented 4 years ago

I tried something very basic one line that just has ipconfig /all. In a bat file this works fine, in powershell script this loops.

ryanblenis commented 4 years ago

Can you share the script you were using and some info about the client system?

I tried with "ipconfig /all" in bat and powershell and both return as expected (on a Win10 1909 x64 client system).

Thanks

vish84 commented 4 years ago

The script only has ipconfig /all one line, for testing

I done some further testing, on windows 10 this seems to execute the ps script correctly On windows 7 x64 is see where I see this issue

I have ensured when testing on both machines powershell execution has been set to unrestricted

luismanson commented 3 years ago

Hello, thanks for your plugins, it's very useful!. I can confirm this issue, a PS script on win7 will make scripts run forever, there should be an option to kill/clear the job if its not working right.

There should be an option to clear this tasks or enable debug

ryanblenis commented 3 years ago

I'll have to look at the option to force stop/kill a task in progress.

As for Win7 support. Win7 was end-of-life'd before I made this plugin, so I didn't do any much testing with it. I'd likely need to see if I have an older machine or a VM with 7 on it in order to test. (If it should even be supported at this point, as I don't think Win7 should be running anywhere due to EOL and potential security concerns at this point from an unsupported OS standpoint).

There is an option to enable debugging on the specific endpoint having an issue. From the device's console screen you can type plugin scripttask debug to toggle debugging on the endpoint. Which, when enabled, will output some more information into the MeshAgent folder's \scripttask.txt file.

easy124 commented 3 years ago

Sometimes scripts will run forever on Windows 10 too, for example, if a batch accidentally requires input to continue (thus never finishing/progressing), scripttask will re-send the script to the client repeatedly, creating thousands of temporary batch files and running processes, and eventually fill the disk/RAM. Happens a lot to me since some commands I'm using are inconsistent. Similarly happens with powershell the only way to stop it is to edit the .json file containing the tasks Otherwise, absolutely love the plugin

SpookOz commented 3 years ago

Hi Ryan. I can confirm I have also had a script run in a loop. In my case it was a batch file. I turned on debugging and got the following lines before the user rebooted their PC:

2021-06-01 15:47:24.645+10:00: Running Script a9qMpi5FEpIcOxSq 2021-06-01 15:49:30.339+10:00: Running Script a9qMpi5FEpIcOxSq 2021-06-01 15:50:24.928+10:00: Got process list 2021-06-01 15:50:24.928+10:00: There are currently 1 running jobs. 2021-06-01 15:50:24.928+10:00: Checking for running job: Zkv2yG6VFBXGM3qQ with PID 10696 2021-06-01 15:50:24.928+10:00: Found job with no process. Removing running status. 2021-06-01 15:50:24.928+10:00: Running Script a9qMpi5FEpIcOxSq

SpookOz commented 3 years ago

Just an update. After a reboot, the task is still running in a loop and I'm not quite sure how to stop it. I've deleted the script from ScriptTask and run plugin scripttask clearAll in the console. Here is the output of scripttask.exe at this point:

2021-06-01 15:47:24.645+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-01 15:49:30.339+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-01 15:50:24.928+10:00: Got process list

2021-06-01 15:50:24.928+10:00: There are currently 1 running jobs.

2021-06-01 15:50:24.928+10:00: Checking for running job: Zkv2yG6VFBXGM3qQ with PID 10696

2021-06-01 15:50:24.928+10:00: Found job with no process. Removing running status.

2021-06-01 15:50:24.928+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-01 15:51:24.937+10:00: Got process list

2021-06-01 15:51:24.937+10:00: There are currently 1 running jobs.

2021-06-01 15:51:24.937+10:00: Checking for running job: Zkv2yG6VFBXGM3qQ with PID 9572

2021-06-01 15:51:24.946+10:00: Found job with no process. Removing running status.

2021-06-01 15:51:24.946+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 09:52:45.015+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 09:53:43.264+10:00: Got process list

2021-06-04 09:53:43.264+10:00: There are currently 1 running jobs.

2021-06-04 09:53:43.264+10:00: Checking for running job: Zkv2yG6VFBXGM3qQ with PID 4656

2021-06-04 09:53:43.264+10:00: Found job with no process. Removing running status.

2021-06-04 09:53:43.264+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 09:54:41.022+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 09:55:39.076+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 09:56:37.416+10:00: Got process list

2021-06-04 09:56:37.416+10:00: There are currently 1 running jobs.

2021-06-04 09:56:37.416+10:00: Checking for running job: Zkv2yG6VFBXGM3qQ with PID 8388

2021-06-04 09:56:37.416+10:00: Found job with no process. Removing running status.

2021-06-04 09:56:37.416+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 09:57:35.568+10:00: Got process list

2021-06-04 09:57:35.568+10:00: There are currently 1 running jobs.

2021-06-04 09:57:35.568+10:00: Checking for running job: Zkv2yG6VFBXGM3qQ with PID 3888

2021-06-04 09:57:35.568+10:00: Found job with no process. Removing running status.

2021-06-04 09:57:35.568+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 09:58:35.268+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 09:59:35.274+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:00:35.288+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:01:35.273+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:02:35.272+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:03:35.281+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:04:35.569+10:00: Got process list

2021-06-04 10:04:35.569+10:00: There are currently 1 running jobs.

2021-06-04 10:04:35.569+10:00: Checking for running job: Zkv2yG6VFBXGM3qQ with PID 8404

2021-06-04 10:04:35.569+10:00: Found job with no process. Removing running status.

2021-06-04 10:04:35.569+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:05:35.699+10:00: Got process list

2021-06-04 10:05:35.699+10:00: There are currently 1 running jobs.

2021-06-04 10:05:35.699+10:00: Checking for running job: Zkv2yG6VFBXGM3qQ with PID 4492

2021-06-04 10:05:35.699+10:00: Found job with no process. Removing running status.

2021-06-04 10:05:35.699+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:06:35.756+10:00: Got process list

2021-06-04 10:06:35.756+10:00: There are currently 1 running jobs.

2021-06-04 10:06:35.757+10:00: Checking for running job: Zkv2yG6VFBXGM3qQ with PID 5932

2021-06-04 10:06:35.757+10:00: Found job with no process. Removing running status.

2021-06-04 10:06:35.757+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:07:35.748+10:00: Got process list

2021-06-04 10:07:35.748+10:00: There are currently 1 running jobs.

2021-06-04 10:07:35.748+10:00: Checking for running job: Zkv2yG6VFBXGM3qQ with PID 15636

2021-06-04 10:07:35.748+10:00: Found job with no process. Removing running status.

2021-06-04 10:07:35.748+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:08:35.283+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:09:35.280+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:10:35.232+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:11:35.162+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:12:35.097+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:13:35.043+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:14:35.513+10:00: Got process list

2021-06-04 10:14:35.513+10:00: There are currently 1 running jobs.

2021-06-04 10:14:35.513+10:00: Checking for running job: Zkv2yG6VFBXGM3qQ with PID 12236

2021-06-04 10:14:35.513+10:00: Found job with no process. Removing running status.

2021-06-04 10:14:35.513+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:15:34.971+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:16:35.407+10:00: Got process list

2021-06-04 10:16:35.407+10:00: There are currently 1 running jobs.

2021-06-04 10:16:35.407+10:00: Checking for running job: Zkv2yG6VFBXGM3qQ with PID 2512

2021-06-04 10:16:35.407+10:00: Found job with no process. Removing running status.

2021-06-04 10:16:35.415+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:17:34.963+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:18:35.514+10:00: Got process list

2021-06-04 10:18:35.514+10:00: There are currently 1 running jobs.

2021-06-04 10:18:35.514+10:00: Checking for running job: Zkv2yG6VFBXGM3qQ with PID 6212

2021-06-04 10:18:35.514+10:00: Found job with no process. Removing running status.

2021-06-04 10:18:35.514+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:19:35.481+10:00: Got process list

2021-06-04 10:19:35.481+10:00: There are currently 1 running jobs.

2021-06-04 10:19:35.497+10:00: Checking for running job: Zkv2yG6VFBXGM3qQ with PID 3348

2021-06-04 10:19:35.497+10:00: Found job with no process. Removing running status.

2021-06-04 10:19:35.497+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:20:35.487+10:00: Got process list

2021-06-04 10:20:35.487+10:00: There are currently 1 running jobs.

2021-06-04 10:20:35.487+10:00: Checking for running job: Zkv2yG6VFBXGM3qQ with PID 12112

2021-06-04 10:20:35.487+10:00: Found job with no process. Removing running status.

2021-06-04 10:20:35.487+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:21:34.972+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:22:34.957+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:23:34.971+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:24:34.971+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:25:34.965+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:26:35.617+10:00: Got process list

2021-06-04 10:26:35.618+10:00: There are currently 1 running jobs.

2021-06-04 10:26:35.619+10:00: Checking for running job: Zkv2yG6VFBXGM3qQ with PID 14568

2021-06-04 10:26:35.619+10:00: Found job with no process. Removing running status.

2021-06-04 10:26:35.620+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:27:34.972+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:28:34.974+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:29:34.975+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:30:34.973+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:31:35.503+10:00: Got process list

2021-06-04 10:31:35.503+10:00: There are currently 1 running jobs.

2021-06-04 10:31:35.503+10:00: Checking for running job: Zkv2yG6VFBXGM3qQ with PID 15468

2021-06-04 10:31:35.503+10:00: Found job with no process. Removing running status.

2021-06-04 10:31:35.503+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:32:34.984+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:33:34.982+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:34:34.987+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:35:34.984+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:36:34.989+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:37:34.979+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:38:34.980+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:39:34.989+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:40:34.981+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:41:34.982+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:42:34.978+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:43:34.980+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:44:34.998+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:45:34.989+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:46:34.995+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:47:35.000+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:48:35.000+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:49:35.003+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:50:35.006+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:51:35.004+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:52:35.009+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:53:35.011+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:54:35.005+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:55:35.005+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:56:34.999+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:57:35.012+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:58:35.017+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 10:59:35.004+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 11:00:35.004+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 11:01:35.772+10:00: Got process list

2021-06-04 11:01:35.773+10:00: There are currently 1 running jobs.

2021-06-04 11:01:35.773+10:00: Checking for running job: Zkv2yG6VFBXGM3qQ with PID 19088

2021-06-04 11:01:35.773+10:00: Found job with no process. Removing running status.

2021-06-04 11:01:35.773+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 11:02:35.008+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 11:03:35.016+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 11:04:35.015+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 11:05:35.027+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 11:06:35.022+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 11:07:35.021+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 11:08:35.019+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 11:09:35.034+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 11:10:35.037+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 11:11:35.029+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 11:12:35.126+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 11:13:35.032+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 11:14:35.038+10:00: Running Script a9qMpi5FEpIcOxSq

2021-06-04 11:14:43.408+10:00: Could not unlink files, error was: fs.unlinkSync(): Error trying to unlink: strqcsjqvj1co.bat

cgb commented 3 years ago

I can reproduce the symptoms of running forever by sending a powershell snippet calling Set-TimeZone

However I can successfully clear the forever 'running' task by calling plugin scripttask clearAll in the console.

I also run some simple batch files and they seem to work without issue though. I haven't ever debugged scriptTask or the plugin execution to offer any further advise :(

For the forever running issue, it would good to set an upper limit on execution time to avoid the tmp files from filling up.

diegogyn commented 1 month ago

I am facing the same problem. Some scripts seem to run forever. If I create a .bat with gpupdate /force command the script never stops.

There is something wrong with the plugin, because when I connect it to the computer terminal with meshcentral and run the script it works as it should.