How to script Unix Executable that requires input?

djrory
Contributor

I have a uninstaller that is a Unix executable but it prompts for confirmation.

Do you wish to continue (yes/no)?

So when I have a script call the executable it just hangs forever, how can I script it so the uninstaller runs correctly?

I've tried

sudo "./Uninstall -Yes"

and

sudo "./Uninstall -Y"

No luck. any advice would be appreciated. 0ca028f22233463097df5a76c77d938a

3 REPLIES 3

shaquir
Contributor III

Hi @djrory ,
You could try:

#Respond to Yes or No prompt with a sleep time of 5 seconds
(sleep 5; printf "Yes") | "/path/to/uninstaller"

Not sure if this is the same program, but is there a uninstall.sh, that'd probably be your best bet

sudo "/Library/Application Support/Checkpoint/Endpoint Security/uninstall.sh"

djrory
Contributor

@shaquir I found that out just after I posted this, Uninstaller seems to just call the uninstall script with the line

sudo "./uninstall" --uninstall

So I put that in the script and it worked.

Thanks for the response though, always handy to know!

wmehilos
Contributor

It's something I've never needed to really write myself, but I believe expect might be a solution for what you need. It used to be needed when accepting the Xcode license automagically with a script, since xcodebuild used to require someone enter "accept" into the Terminal window.

You'd want something like this as a script body:

/usr/bin/expect -f

set timeout -1

spawn ./path/to/your/interactive/script.sh

expect "Do you wish to continue (yes/no)"

send "yes
"

expect eof