Give specific string to script

mkolb
Contributor

Hello,

At the moment I'm facing some troubles with a script. I want to uninstall the EndPointProtector from CoSoSys.

They provide a remove script, which I want to start from a JSS script. The problem: you have to enter a pre-defined uninstall password. How could I pass this from my script to the other script?

I already tried something like this:

#The uninstall password
unpw="xxxxxx"

#This calls the EPP uninstaller script
cd /Library/CoSoSys/EndpointProtector/
echo "$unpw
" | ./remove-epp

But it didn't worked. I guess the problem is "remove-epp" is no command but an other script, so basically my script hands over the string to the launch command of the other script but not to the input method inside this remove-eps script...

Any ideas how I could solve this? It causes a lot of troubles right now for us....

1 ACCEPTED SOLUTION

Nix4Life
Valued Contributor

@mkolb you might want to look at expect or passing the info via EOF.
Below is an example of how I used it in a self-destructing script to enroll via command line a few years ago:

#!/bin/sh
sudo jamf enroll -prompt << EOF
jssacountuser
jssacountuserpassword
localsshaccount
localsshaccountpassword
sleep 5
rm "$0"

View solution in original post

5 REPLIES 5

Nix4Life
Valued Contributor

@mkolb you might want to look at expect or passing the info via EOF.
Below is an example of how I used it in a self-destructing script to enroll via command line a few years ago:

#!/bin/sh
sudo jamf enroll -prompt << EOF
jssacountuser
jssacountuserpassword
localsshaccount
localsshaccountpassword
sleep 5
rm "$0"

mkolb
Contributor

hi,

Thank you @Nix4Life ! I was able to solve this with expect. Thank you for the hint!

rob_c28
New Contributor II

@mkolb Do you mind sharing what you did here using expect?

@mkolb I would love to know the answer to this as well.

mkolb
Contributor

@markopolo / @rob_c28 
Sure! This is how it worked in the end:

expect <(cat <<'EOD'
spawn "./remove-epp"
expect "Please enter your password for uninstall protection:" {send "####\r"}
EOD
)

 

The spawn command starts the actual remove-script. At some point this remove-script will present the string "Please enter your password for uninstall protection:" in the terminal. The expect command is looking for exactly this string (you have to make sure, what ever dialog is showing up, you copy it 1:1 and case sensitive). With the send command you then can define which string should be "typed". The # represents the actual password, the \r represents pressing enter after "typing" the string.

Hope this helps!