Skip to main content
Answer

Created a script to add computer to OD, but....

  • July 5, 2018
  • 8 replies
  • 40 views

salmon
Forum|alt.badge.img+9

I created a script to add to OD, but when I manually run, I get a message "Certificates are available for this server. Would you like to add them to the system keychain automatically (y/n)?"
The script will wait for a response. How can I automatically respond to this question in the script so it does not wait for a response?

Best answer by ryan_ball

You might be able to use expect.

#!/bin/bash

# Some code here

/usr/bin/expect >/dev/null 2>&1 <<EOF
    set timeout -1
    spawn 'command that adds computer to OD without quotes'
    expect "automatically (y/n)?"
    send -- "y
"
    expect eof
EOF

# Rest of code here

exit 0

8 replies

Forum|alt.badge.img+13
  • Honored Contributor
  • July 5, 2018

I hope this can help u:

Jamf Cert discussion


salmon
Forum|alt.badge.img+9
  • Author
  • Contributor
  • July 5, 2018

Yes and no, is there a way to just add a "y" to input into the pause?


Forum|alt.badge.img+13
  • Honored Contributor
  • July 6, 2018

@salmon Create a package with the cert you want to install and put it on the local machine somewhere (tmp)
Read the last response in the thread for a hint as to how to install them after that (read them all for clarity though)


salmon
Forum|alt.badge.img+9
  • Author
  • Contributor
  • July 6, 2018

Thank you, I did read it.


sdagley
Forum|alt.badge.img+25
  • Jamf Heroes
  • July 6, 2018

@salmon My apologies, I misread your question as asking about acknowledging a GUI dialog prompt to the user. The approach @ryan.ball describes below should do what you want to acknowledge a (y/n) prompt in a bash script.


Forum|alt.badge.img+18
  • Contributor
  • Answer
  • July 9, 2018

You might be able to use expect.

#!/bin/bash

# Some code here

/usr/bin/expect >/dev/null 2>&1 <<EOF
    set timeout -1
    spawn 'command that adds computer to OD without quotes'
    expect "automatically (y/n)?"
    send -- "y
"
    expect eof
EOF

# Rest of code here

exit 0

salmon
Forum|alt.badge.img+9
  • Author
  • Contributor
  • July 9, 2018

Thank you, I will give that a try this morning!


salmon
Forum|alt.badge.img+9
  • Author
  • Contributor
  • July 9, 2018

That worked perfectly for what I was doing! Thank you so much ryan.ball!