I am scping files using the exec Ant task. It is working fine, but the output of the scp command is not displayed.
Below is the code
<target name="scp-jar" depends = "jar">
<exec executable="/usr/bin/scp">
<arg value="my.jar"/>
<arg value="myserver:dir"/>
</exec>
</target>
What changes I have to make to display the file progress output of the scp command?
By default, the output of the command gets written to the stdout and you can specify an output attribute to change it to a file. More details here: http://ant.apache.org/manual/Tasks/exec.html
It is difficult to redirect SCP's output though. You might probably want to use the flag -v in your case.
The ant SCP task can show that information. User verbose flag.
This task require additional jars ( jsch.jar 0.1.42 or later)
As #Tanuki Software mentioned, scp wouldn't print the progress bar if stdout isn't tty.
So the problem was more with scp and not with the Ant task.
I tried using the -v option of scp, but it is displaying debugging information and the progress bar.
So there are only two options
Use Exec task and miss out the progress bar. (or)
Use Scp task, but it requires extra jar, doesn't work properly in mac and very difficult to make it use the default settings from .sshconfig file.
I ended up choosing the first option.
Related
In ant when running a command with the exec task anything written to stdout or stderr in the child process has " [exec] " prepended to every line written to both the console and the log file. Is there a way to suppress this behavior or explicitly supply the prefix? (ie: to "" or maybe just an indent)
This is because an ant build run in an IDE the prefix scrambles the ability of the IDE to jump to source files by clicking on the output error messages from javac and other compilers
You may run ant with -emacs option.
However in this case it will suppress the prefix for all tasks.
Otherwise you may implement your own log handler.
In an interactive terminal on MacOS, I successfully sidestepped the Ant log-wrapping mechanism on the exec task by means of the /dev/stdout and /dev/stderr devices, as follows:
<exec executable="python" output="/dev/stdout" error="/dev/stderr">
<arg line='myscript.py' />
</exec>
This will probably also work on Linux, though I havn't explicitly tested it.
On Windows it also works using output="con" error="con" (though in my case, tty codes from my script won't work in a Windows cmd terminal).
I was given a large set of project ant scripts. The script uses a number of sshexec and scp calls to remote machines. I need to change it to enable the program to run locally if needed, so i want to intercept these remote calls and replace sshexec with exec, scp with cp.
a sample call would be:
<sshexec host="${host}" username="${username}" password="${password}" trust="true" usepty="true" command="echo '${password}' | sudo -S ntpdate ${maintain.sync-time.server}" failonerror="false" />
I would need to be able to check if ${host} is remotehost or localhost, if localhost I use exec instead
now the problem is: is there a way to avoid changing all the calls one by one (they are littered in the project) or is there a way to intercept the call, check the variable then decide to use sshexec or exec?
Create a new Ant Task in java then do a regex replace on your build scripts ?
I have an ant build script that connects to a remote server and kicks off a local build using SSHExec. This build takes approximately 1 minute and it sends me an email when it's completed, but the ant task I have:
<sshexec
host="${deploy.host}"
username="${deploy.username}"
trust="true"
keyfile="${user.home}/.ssh/id_rsa"
command="~/updateGit.sh"/>
Will wait until the script is completed. I tried passing a & like so (I assume I have to escape it in a build.xml):
<sshexec
host="${deploy.host}"
username="${deploy.username}"
trust="true"
keyfile="${user.home}/.ssh/id_rsa"
command="~/updateGit.sh &"/>
But this doesn't seem to make a difference. In case this extra detail helps anyone, the script generates a lot of output and a slow internet connection can cause the script to take a lot longer (as it's output is being piped back, the assumption with this approach is that I only care about the output after its done, so if I pack it up into an email I can monitor my inbox as builds get kicked off, basically it's a poor-man's Continuous Integration)
Using information from this answer (and the nohup command) I updated my task as follows:
<sshexec
host="${deploy.host}"
username="${deploy.username}"
trust="true"
keyfile="${user.home}/.ssh/id_rsa"
command="nohup ~/updateGit.sh > /dev/null 2> error.log < /dev/null &"/>
Is it possible to modify the current shell with system calls in Lua?
More specifically, in the current environment expand_aliases is false by default but some scripts depend on the ability to set aliases. Is it possible to issue a command like os.execute("shopt -s expand_aliases") at the beginning of those scripts that would affect the current shell thus allowing the current script to add a bash alias?
Both setting expand_aliases globally to true as well as setting expand_aliases in bash before executing the script aren't quite desired solutions.
Thanks in advance for any help.
You could open a pipe to a shell and then send both your configuration settings and your scripts to it. But you cannot affect the current shell.
When I run my build file, it always shows the target name.
For example, in my build file if I have targets A, B, C.
Then on when I type the command ant A, it shows
A: <...whatever>
How do I avoid displaying the A?
Any help is very much appreciated.
The command line switch is -q
$ ant -q A
A few options:
try -q for quiet mode
try -emacs (not sure if this dumps the targets or not, but worth trying)
write a custom logger
You might also have a look at the following blog entry http://codefeed.com/blog/?p=82. The author provides some code for a custom task to set the loglevel in a build script. This way you can enable and disable log output for specific operations.