1

I am trying to automate domain join but want to make it so you cannot run some commands twice. I am trying to stop the script if the domain is already joined. Printed text if domain is already joined: realm: Already joined to this domain

#!/bin/bash
yum install realmd oddjob oddjob-mkhomedir sssd samba-common-tools -y

Type the domain you want to join. You will be asked for the user password.

read -p "Enter the domain you want to join : " domain_name realm join -U admin $domain_name

<==> STOP HERE IF PRINTED TEXT IS= realm: Already joined to this domain

sed -i "111i %Linux-Admins@domain ALL=(ALL) NOPASSWD: ALL" /etc/sudoers sed -i '$ a+ : domain\Linux-Admins : ALL\n+ : root : ALL\n- : ALL : ALL' /etc/security/access.conf sed -i '/account required pam_unix.so/s/$/ broken_shadow/' /etc/pam.d/system-auth-ac sed -i '/account required pam_permit.so/a account required pam_access.so' /etc/pam.d/system-auth-ac sed -i '/account required pam_unix.so/s/$/ broken_shadow/' /etc/pam.d/password-auth-ac sed -i '/account required pam_permit.so/a account required pam_access.so' /etc/pam.d/password-auth-ac sed -i -e '/GSSAPIAuthentication/s/yes/no/' /etc/ssh/sshd_config systemctl stop realmd.service oddjobd.service sssd.service sshd.service systemctl start realmd.service oddjobd.service sssd.service sshd.service systemctl status realmd.service oddjobd.service sssd.service sshd.service

1 Answers1

1

You need something like this:

res=`realm join -U admin $domain_name 2>&1`
if [[ $res == *"realm: Already joined to this domain"* ]]; then
        echo done
        exit 0
fi
fratester
  • 384