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.
More on Scheduling, automation and scripting
A database dump must run every night at 1:30 AM. How do you schedule it with cron so it is reliable?BeginnerConvert that nightly cron job to a systemd timer. Why would you?IntermediateA cron job runs every 5 minutes, but sometimes takes 8 minutes and two copies overlap, corrupting data. How do you prevent that?BeginnerYou have 300 servers running the same cron job at midnight, and they hammer a shared API. How do you fix it?IntermediateA job must run on the last day of every month. Cron has no "last day" field. What do you do?IntermediateYou inherited a server and need to know every scheduled job on it. Where do you look?Beginner