I mean, how to dynamically stop a running shell script based on what operation it's doing. Because some dangerous commands such as rm, if using regex before running, some edge situations may escape, like

$name rm a.py

will still remove a.py.

So is there a way to detect what the next command is of a running script and stop it if matches.

Maybe complex regex can do this before running, but I want to know if there is a nice solution with running scripts.


I am not allowed to modify the scripts because it was given by others.


You shouldn't run untrusted third-party scripts in the first place.

Filtering shell calls might be achieved when they lead to forking other binaries using AppArmor, SELinux, GrSec or other security policing tools.

However pure bash can do way too much without forking for it to be enough.

Don't run the script or read it before you run it. If you don't trust the third-party provider but must run it, you're left with reading it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.