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/bash
IP=`cat prod_ips.txt`
check=`ls /etc | grep ^AD`
for i in $IP;
do
echo '------------------------------------------------------------';
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 $check
if [ -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";
fi
echo '------------------------------------------------------------';
echo "";
done;
Sample output:
------------------------------------------------------------
Connecting to <IP>
Authorized uses only. All activity may be monitored and reported.
sudo: adleave: command not found
Connection to <IP> closed.
AD_joined
File still present, something went wrong
------------------------------------------------------------