tags:

views:

813

answers:

1

I'm using the SSHEXEC ant task to run an SSH script against a remote linux box.

This has worked fine until I try and call a ksh script which prompts the user for input. The script changes the current user (like su). It prompts the user for a change_request_id, and a change_request_reason. So using this command normally in a shell would look like this:

change_user deploy_user
Please enter the changes request number for doing this: 1234
Please enter the changes request reason: Because I can
<deploy_user>

But when I run these commands from SSHEXEC, it gets to the first prompt "Please enter the changes request number for doing this:" and stops. Even though I'm piping a response to this prompt via SSHEXEC, it still gets stuck here.

Unfortunately we do not have access to change or copy the change_user shell script.

I was wondering if there was some way I could use SSHEXEC which would send down prompt answers with the command.

Any help would be appreciated.

+1  A: 

Are you able to put another script on the same server as the change user script that accepts command line parameters and then calls the change request script itself? E.g. in ksh:

#!/usr/bin/ksh
#
# $1 is change request number
# $2 is change request reason
#
/path/to/change_request_cmd <<PARAMS
$1
$2
PARAMS

It may be easier to have SSHEXEC call this script instead.

William Rose
Thanks William. Your solution looks ideal, however when I tried it, it broke as the script I am running changes the current user, so it errors before it finishes. Apart from this problem your solution does indeed allow me to answer script prompts. I guess it's now a matter of working around this change user problem! Cheers.
You can set up sudo to let you run that command as another user -- e.g. prefix the /path/to/change_request_cmd with sudo -u otheruser, and configure an /etc/sudoers to allow this without a password.
William Rose