sudo i permessi riguardano l'utente/gruppo da cui stai cambiando da non l'utente che stai cambiando in .
Quindi quelle righe di autorizzazione lasciano il testuser utente e il testgroup il gruppo esegue qualsiasi comando (come chiunque) senza password.
Devi dare il permesso a l'utente che esegue lo script per eseguire i comandi come il testuser utente per quello che vuoi.
Supponendo che fosse quello che intendevi permettere.
Questo errore si verifica quando il tuo file sudoers specifica requiretty . Dal sudoers manpage:
requiretty If set, sudo will only run when the user is logged in to a real tty. When this flag is set, sudo can only be run from a login session and not via other means such as cron(8) or cgi-bin scripts. This flag is off by default.
Per correggere l'errore, rimuovi requiretty dal tuo file sudoers.