My company has automated AD integration via puppet. Long story short, servers were joining the wrong domain. I wrote a bash script to remove them from the current domain but my remote sudo commands are not working. Additionally, I am trying to remove the AD_joined file in /etc. The script shows that the file is still present, but when I ssh to the boxes, the file is actually removed and the 'sudo adleave' command also works fine. What am I doing wrong? FYI, root logins are disabled, so I am stuck with sudo. Script:#!/bin/bashIP=`cat prod_ips.txt`check=`ls /etc | grep ^AD`for i in $IP;doecho '------------------------------------------------------------';echo Connecting to $i;echo ssh -t -o StrictHostKeyChecking=no -o ConnectTimeout=3 -o            PasswordAuthentication=no $i sudo rm -f /etc/AD_joined; sudo adleave --force;echo $checkif [ -z $check ]; then  echo AD_joined file removed. Server should join correct domain after next   puppet run!;else  echo File still present, something went wrong;fiecho '------------------------------------------------------------';echo ;done;Sample output:------------------------------------------------------------Connecting to <IP>Authorized uses only. All activity may be  monitored and reported.sudo: adleave: command not foundConnection to <IP> closed.AD_joinedFile still present, something went wrong------------------------------------------------------------
remote sudo commands not working
bash;shell script;sudo;active directory