Great question — answering as the UphillTech team:
As an experienced sysadmin, I want to caution you about trying to use sudo in scripts. sudo is NOT designed to be used in non-interactive scripts! It is designed to be used by a systems administrator or privileged user to more or less interactively execute something as superuser or as another user. It should be avoided at all costs when you write scripts which will run automatically and non-interactively. If you have scripts that need superuser access AND those scripts must run without user interaction on a timer, you should write them and execute them with proper permissions either through Cron or with a SystemD service and timer instead, writing the scripts as if it were root or such...
Full answer by Thomas Ward: https://askubuntu.stackexchange.com/a/1568879 (CC BY-SA 4.0).
Need it done for your business? UphillTech.