Friends, thank you all for your help. I solved the problem through digital outputs and remap.
Something like this -
O<auto_control_off> SUB
M65 P0
O<auto_control_off> ENDSUB
M2
//
O<auto_control_on> SUB
M64 P0
O<auto_control_on> ENDSUB
M2
//
[RS274NGC]
PARAMETER_FILE = linuxcnc.var
RS274NGC_STARTUP_CODE = G21 G40 G90 G94 G97 G64 P0.025
USER_M_PATH =/home/pi/linuxcnc/configs/GRINDER_CNC/macros
SUBROUTINE_PATH =/home/pi/linuxcnc/configs/GRINDER_CNC/macros
REMAP = M20 modalgroup=10 ngc=auto_control_on
REMAP = M21 modalgroup=10 ngc=auto_control_off
But another task appeared - to run scripts for turning off bits when pressing the "Stop" or "Emergency stop" button. It is necessary to stop additional equipment, as for example, the spindle and cooling stop.