Will preface here stating that this is poor practice but I have been requested anyway to store the svc-account credential within the script which will live in vRA for VM template.. not my choice, but due to use case, there cannot be user input. I am currently trying to use expect to send the svc account password. I see the prompt, and the script completes without error, but does not join the domain.. I am not sure if it is sending the credentials set as variable...


yum -y install sssd realmd oddjob oddjob-mkhomedir adcli samba-common samba-common-tools krb5-workstation openldap-clients python3-policycoreutils expect

OU="OU=Computers,OU=Object Staging, DC=test,DC=acme,DC=com"

echo "OU selected is: $OU "

export OU

expect -c '

set OU "Computers,OU=Object Staging, DC=test,DC=acme,DC=com"

set PASS bugsBunny

spawn sudo realm join --user=svc-domainJoin --computer-ou="\$OU" test.acme.com ;

expect "Password for svc-domainJoin:"; send {"$PASS"\r\"; interact } ;
realm list

additionally, I am not seeing the output of realm list after; when I ran this script without expect (and user input); this cmd did execute

  • The quoting for the send command is wrong. Try send "$PASS\r"; interact Commented Jul 26, 2022 at 15:42
  • Thank you! that did work and appreciate your response as I'm learning through this. The other answer did illuminate that I do not need expect here Commented Jul 26, 2022 at 16:12
  • @onceIHadASoul94 you seem to be happy with the answer offered below. Please consider accepting it with the ✔ mark, as that's how we say "thank you" here on the StackExchange sites Commented Jul 26, 2022 at 22:17

1 Answer 1


You do not need expect. These commands accept directly from STDIN the password:

OU="Computers,OU=Object Staging, DC=test,DC=acme,DC=com"
printf "%s\n" "$PASS" |sudo realm join --user=svc-domainJoin --computer-ou="\$OU" test.acme.com

And probably you do not need this backslash before OU

printf "%s\n" "$PASS" |sudo realm join --user=svc-domainJoin --computer-ou="$OU" test.acme.com
  • 1
    Thank you very much! Commented Jul 26, 2022 at 16:12
  • 1
    @onceIHadASoul94, if you are happy with my answer and in reasonable time you do not like any other answer feel free to accept mine Commented Jul 26, 2022 at 16:15
  • @roaima, probably its a error (the backslash) Commented Jul 26, 2022 at 16:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .