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

salmon
New Contributor III

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?

1 ACCEPTED SOLUTION

ryan_ball
Valued Contributor

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

View solution in original post

8 REPLIES 8

CapU
Contributor III

I hope this can help u:

Jamf Cert discussion

salmon
New Contributor III

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

CapU
Contributor III

@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
New Contributor III

Thank you, I did read it.

sdagley
Esteemed Contributor II

@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.

ryan_ball
Valued Contributor

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
New Contributor III

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

salmon
New Contributor III

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