我的公司通过木偶实现了自动化 AD 集成。长话短说,服务器加入了错误的域。我编写了一个 bash 脚本来将它们从当前域中删除,但我的远程sudo
命令不起作用。此外,我正在尝试删除 /etc 中的 AD_joined 文件。该脚本显示该文件仍然存在,但是当我通过 ssh 连接到盒子时,该文件实际上已被删除,并且“sudo adleave”命令也可以正常工作。我究竟做错了什么?仅供参考,root 登录被禁用,所以我只能使用sudo
.
脚本:
#!/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;
示例输出:
------------------------------------------------------------
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
------------------------------------------------------------
答案1
阅读对您的第一篇文章的评论:您是否尝试/usr/sbin/adleave
在脚本中使用而不是adleave
.