Shell Script sometimes timeouts itself for no reason, I can't tell why. How to make this 100% reliable?

sampleuserhere

Active member
I have an action block fired by multiple gestures I set up in other app. What this block does is simple, it broadcasts multiple data about the current screen. With this mechanic, I can have other routines fired based on the context of the screen.

Now here's where the problem arises. One of those broadcasted data is foreground application activity, which is retrieved by executing the following line with Shell Script action.

Code:
dumpsys activity activities | grep "mResumedActivity" | cut -d "{" -f2 | cut -d " " -f3 | sed "s/\///g"


Screenshot_2023-09-01-07-45-44-073_com.arlosoft.macrodroid.png

What bothers me the most is that for some unknown reason, Shell Script action timeouts itself occasionally. The code itself works as intended and yet sometimes it fails. I can't tell why at all.

I'd like to have this 100% reliable as I mostly want to trigger some routines on the spot. What approach should I use to do this?

TIA.
 

sampleuserhere

Active member
Screenshot_2023-10-23-12-00-22-731_com.vivaldi.browser.png

Set up a tracker since then, and now I have at least about 6.5k shell scripts executed. Without the helper and in non-root environment.
 

Attachments

  • ShellScript_Monitor.macro
    9.8 KB · Views: 5

LinerSeven

Active member
Hi, @sampleuserhere,

Is it possible that the Dumpsys output results are too large for Grep to complete in time?

How about increasing the timeout period or using a block next action until completion?
( I assume you have already done this..... ).

Best Regards,
Liner Seven
 

Attachments

  • Screenshot_20231023_170959.png
    Screenshot_20231023_170959.png
    160.1 KB · Views: 7

sampleuserhere

Active member
Hi, @sampleuserhere,

Is it possible that the Dumpsys output results are too large for Grep to complete in time?

How about increasing the timeout period or using a block next action until completion?
( I assume you have already done this..... ).

Best Regards,
Liner Seven

MD usually takes about 50-150ms to execute the code, so I haven't tried increasing the timeout from 5 seconds.

The timeout issue I have is not just to limited to the command in OP, Simple command occasionally fails too.

I'll try increasing the timeout and see what happens next.

Anyway, I attached the macro below that executes echo "good". It pushes "bad" to an array and the shell scripts output will set it to "good" if the shell doesn't timeout.

I also had another discussion in below thread back then, but decided to update the post I made in this subforum instead.

 

Attachments

  • Shell_Test_2.macro
    32.8 KB · Views: 4

Endercraft

Moderator (& bug finder :D)
@sampleuserhere results from 752 entries.
100% success rate... I don't understand why you and a few others have this problem specifically. Maybe a factory could fix it?
 

sampleuserhere

Active member
@sampleuserhere results from 752 entries.
100% success rate... I don't understand why you and a few others have this problem specifically. Maybe a factory could fix it?

That's what I'd like to know. Even a simple echo timeouts occasionally too in the same environment (no root & without the helper ) and I couldn't tell at all what causes this. I've done a factory reset already since I once rooted my phone at the beginning of this month. Same results.

Anyway which macros did you use though?
 

sampleuserhere

Active member
Checked the bad count with echo '{lv=log}' | grep -c "bad" and based on that, you had about 6 out of 960 exes that didn't set "good", that's honestly a way better number than mine.
 

Endercraft

Moderator (& bug finder :D)
I've just seen that, I finally remembered that there is a search function in the array variable. It is possible that due to me rebooting and killing MD it doesn't have time to execute the shell script into the variable. Saving of macros and variables also doesn't occur instantly (every few seconds) so that may be the cause.
 

Dev777

Active member
This is the script. It's working most of the times but at times I realise that my macro is misbehaving and when I go to the logs that's what I get. I'll try using Termux-tasker instead to see if it will be fixed
 

Attachments

  • Screenshot_2023-10-24-20-55-26-147_com.arlosoft.macrodroid.jpg
    Screenshot_2023-10-24-20-55-26-147_com.arlosoft.macrodroid.jpg
    505.5 KB · Views: 7

sampleuserhere

Active member
I've just seen that, I finally remembered that there is a search function in the array variable. It is possible that due to me rebooting and killing MD it doesn't have time to execute the shell script into the variable. Saving of macros and variables also doesn't occur instantly (every few seconds) so that may be the cause.

I guess the number you would have wouldn't be all that different either when you use the shell monitor I sent or the one I sent below.

The first reacts to system log's content while the later reads the system log directly. The later needs to be manually configured since we have to pick the directory for the export log. Both should be more reliable than the test macro.
 

Attachments

  • ShellScript_Rate.macro
    7.3 KB · Views: 2
Top