Ant exec task as another user - ant

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?

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.

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.

Related

How to use ANT to save current process run time?

How to save current process running time in some text file using Ant, then read file and assign to Ant variable?
You can use ant exec task. There you can specify the executable ps and the necessary arguments (PID, options). You can check the argumengs here.
You specify outputproperty in ant exec task so the output will be redirected to this property.
Then you can put the value in a file using the echo task.

sshexec command - ftp get as parametes

In my code am using something like
<sshexec host="somehost"
username="dude"
password="yo"
command="ftp_download"/>
<ftp action="get" server="server_todownload" userid="user" password="aaa" remotedir="dowload/dir">
<fileset dir="${installerdirectory}"><include name="${file_name}"/></fileset>
</ftp>
In "command" of sshexec how i can pass the ftp action as parameters??
is there any example or document is there to get more knowledge??
Thanks in advance
I guess you want to:
ssh to another machine, and
download something on that machine using ftp.
I think you misunderstood something. <sshexec> is a task that sshes to a machine and executes a command on that machine. The command it executes must exist on that machine. For example, your code:
<sshexec host="somehost" username="dude" password="yo" command="ftp_download"/>
There must be a command named ftp_download existing on somehost or your <sshexec> will fail. You can't use an ant task in your local build file as a parameter because <sshexec> doesn't work in this way at all.
Suggestion:
You can put the ftp task in an ant build file, and deploy it to the remote machine (you can use scp task) before sshexec. In sshexec's command, you write ant -f path_to_build_file ftp_target. You need to ensure that there is ant on that machine.

about ant sshexec

how to specify command in sshexec task of ant to execute an ant task on a remote server machine. like for example:
<sshexec host="somehost"
username="dude"
keyfile="${user.home}/.ssh/id_dsa"
commandResource="to_run"/>
in above code what would be in the command attribute while trying to perform an ant task on a remote server machine, and also if the ant task is to deploy an application
please help me out on this one as the appache site is not of much help.

Is executing a sequence of Commands possible using ANT Exec task

In ANT Exec task. I need to cd into a folder (Windows OS) (eg: D:\Testrun) and execute a set of commands in a sequence which will be passed as parameters to the ant script. Is this possible ? Could anyone quote a sample example ? Could the results of the command execution be logged in a file ?
Could you wrap up the sequence of commands into a script (e.g. a .bat script)? You could pass parameters to the script from your ant task. You could direct the output of the script to a file using the output attribute of the exec task.

Exec task in msbuild TFS won't execute exe properly

I'm using web deploy to a remote server, through which we can only connect through a Cisco VPN client.
In my TFS project file I have an EXEC task to open the client, then one to close it.
<Exec Command="start $(COMSPEC) /C "C:\Program Files (x86)\Cisco Systems\VPN Client\vpnclient.exe" connect profile user me pwd password" ContinueOnError="false" />
Without these EXEC tasks and if I open the connection manually then the deployment works. But these commands aren't opening the client in the build, it just hangs on this task before opening the client.
If I copy this task and paste into a standard build file and call that from msbuild.exe then the client is opened.
Do you know why it won't work in the TFS project when the build is called but it would work manually in a separate build file?
For kicks I would try using the full path to comspec: "C:\Windows\system32\cmd.exe" or whatever path for the OS you are using in the off-chance it is resolving incorrectly.
Also, can you toss in a /k to keep the cmd prompt open and see what, if any, errors show assuming it launches correctly?
I couldn't work this one out. So I used Invoke Process in the XAML template instead. Which has worked fine.

Resources