Interview Prep/Linux/Scheduling, automation and scripting

A script you wrote works for you but fails when run by `sudo` with "command not found". Why?

BeginnerScenarioScheduling, automation and scripting
Answer

Situation read → sudo resets PATH to secure_path.

What I'd do →

sudo grep secure_path /etc/sudoers
sudo env | grep PATH

Use absolute paths in scripts, or install tools into a directory in secure_path (/usr/local/bin).

Why → secure_path stops a user-controlled PATH from tricking root into running a malicious binary.

Interview tip → Don't "fix" it with sudo env PATH=$PATH; that defeats the protection.

All Linux questions Roadmap: Linux

More on Scheduling, automation and scripting