1

I would like to execute a shell script from an ant build (I saw the exec task seems to do it), but this script has to be executed from a user different thant the one launching ant. Is there a way to do this?

kgautron
  • 7,915
  • 9
  • 39
  • 60

2 Answers2

2

Couldn't you execute, from ant, a script that executes the actual script using sudo? See How to pass the password to su/sudo/ssh without overriding the TTY? for how to pass the password from the command line.

Community
  • 1
  • 1
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • I tried this using bash (default terminal) and it works. ANT, however, doesn't seem to be able to execute the trick and seems to not read the password: [exec] [exec] Password: [exec] Sorry, try again. [exec] Password: [exec] Sorry, try again. [exec] Password: [exec] Sorry, try again. – Michahell Oct 27 '12 at 22:23
2

You could use the sshsexec task. Connect locally or to a remote machine:

<sshexec host="localhost"
    username="dude"
    password="yo"
    command="touch somefile"/>

This task will require the optional jsch.jar to be installed in your ANT lib.

Specifying a pirvate key would enable a password-less login.

Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185