ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter reilly <peter.rei...@corvil.com>
Subject Re: Shell Script
Date Fri, 28 Mar 2003 09:19:06 GMT
I think you are nearly there.

First you should do everything on the command
line and log this.

Place the same commands in a sh file (connect.sh for example) and
see if sh connect.sh works.

Then if that works, the script may either be called
by <exec executable="bash">
        <arg value="connect.sh"/>
    </exec>
or the script may be placed in-line in the build file and
use made of <shellscript/>, remembing to excape
any xml characters like '<' and '--'

the ssh client from openssl looks like
ssh [options] host [commands]

If commands  are not present, the ssh program
logons to host and sends the std input to a shell overthere.

in a sh (or bash) script one may place std input to a command
by using the "here document" syntax - see man bash (or google
man bash) for detailed explaination. This is

command << END
 input for the command...
END

The first shellscript you did looks correct except for
missing the "<< END" and not placing the terminating
END at the start of a line.
The following sh script should work.

         ssh -l michaeltaft jyotish.sourceforge.net << END
         cd /home/groups/j/jy/jyotish/htdocs/
         gunzip FJWeb.tar.gz
         tar xf FJWeb.tar
         rm FJWeb.tar
END

placing this inline in a build script means that you must excape
the '<' character as it is a xml token character. This can be
excaped by using &lt; or by placing the text in a CDATA block.
The following should work.

    <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
    <shellscript shell="bash"  output="dir2.txt">
         ssh -l michaeltaft jyotish.sourceforge.net &lt;&lt; END
         cd /home/groups/j/jy/jyotish/htdocs/
         gunzip FJWeb.tar.gz
         tar xf FJWeb.tar
         rm FJWeb.tar
END
         </shellscript>

:::NB:::
at the moment shellscript does not send the in-line text
to the shell as std input. When ant 1.6 is released, shellscript
will be updated to do this.

Peter.

On Thursday 27 March 2003 19:11, Michael Taft wrote:
> Thanks for your help, Peter:
>
> I rewrote the code as best I could, based on your recommendations.  Here
> is what I came up with (that  doesn't work yet):
>
> <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
>         <shellscript shell="bash"  output="dir2.txt">
>         ssh -l michaeltaft jyotish.sourceforge.net
>         cd /home/groups/j/jy/jyotish/htdocs/
>         gunzip FJWeb.tar.gz
>         tar xf FJWeb.tar
>         rm FJWeb.tar
>         END
>         </shellscript>
>
> One thing I'm unsure about is where you say I must define the server.
> I'm not clear which server you mean. Pardon my unpardonable ignorance
> here, but the ssh server on my box gets automatically invoked by the
> command "ssh" (the script works that far). The name of the server I'm
> connecting to is, I think "sc8-pr-shell1" or (as it calls itself in the
> docs) the "SourceForge Project Shell Server". But the "ssh" command I'm
> using is for my home machine (telling it connect to the remote server)
> and all the lines after that are for the sc8-pr-shell1 server. So, what
> I think you're saying is that between those two lines, I need another
> line of code, which redirects the subsequent commands to the new server,
> correct?
>
> I gave it a shot (without a clue what I doing, really, I just copied the
> format of one of your lines, modified it to fit the server name, and
> plugged it in) like this:
>
> <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
>         <shellscript shell="bash"  output="dir2.txt">
>         ssh -l michaeltaft jyotish.sourceforge.net
>         ssh sc8-pr-shell1 &lt;&lt;END
>         cd /home/groups/j/jy/jyotish/htdocs/
>         gunzip FJWeb.tar.gz
>         tar xf FJWeb.tar
>         rm FJWeb.tar
>         END
>         </shellscript>
>
> But clearly that was a failure.
> I feel like I'm almost there on this.
> Further clues?
> Thank you very much for your patient help in the face of a wall of
> ignorance :)
> M.
>
> peter reilly wrote:
> >The "cannot allocate Pseudo-terminal" is just ssh
> >whineing that it is run by a program and not by
> >a terminal (or something that looks like a terminal)
> >
> >You may be hanging in the exec executable="ssh" line
> >because you do not provide std input to ssh, It is now
> >waiting for input but none is provided.....
> >
> >I do not see server defined in your script. Also
> >there is no need to use both exec and shellscript (this
> >may be just an artifice of your testing).
> >
> >Here is a shell script that works for me.
> >
> >  <target name="ssh">
> >    <shellscript shell="bash">
> >      set -x
> >      cd ~/tmp
> >      ssh serv1 &lt;&lt;END
> >         cd /tmp
> >         ls -rlta | grep tt2
> >END
> >    </shellscript>
> >  </target>
> >
> >and the output is:
> >
> >ssh:
> >+ cd /home/preilly/tmp
> >+ ssh serv1
> >Pseudo-terminal will not be allocated because stdin is not a terminal.
> >-rw-r--r--   1 matt      wheel     18624 Mar 13 18:09 tt2
> >
> >BUILD SUCCESSFUL
> >
> >good luck,
> >
> >Peter
> >
> >On Thursday 27 March 2003 07:11, Michael Taft wrote:
> >>Thanks for your reply, Peter.
> >>
> >>I downloaded the shell script task, but I'm having trouble actually
> >>getting it to work properly with sourceforge.net
> >>
> >>I explained what I'm trying to do earlier (it's included at the bottom
> >>of this email) so I won't repeat it here. Here's my target for trying to
> >>accomplish this.
> >>
> >>
> >><target name="web_zip">
> >>          <tar tarfile="${base.dir}/FJWeb.tar" basedir="${web.dir}"/>
> >>          <gzip zipfile="${base.dir}/FJWeb.tar.gz"
> >>src="${base.dir}/FJWeb.tar"/>
> >>    </target>
> >>
> >>    <!-- Upload to SourceForge.net -->
> >>
> >>        <target name="web_release" depends="web_zip">
> >>        <exec dir="${base.dir}" executable="scp"  output="dir.txt">
> >>        <arg line="FJWeb.tar.gz
> >> michaeltaft@jyotish.sourceforge.net:/home/groups/j/jy/jyotish/htdocs/"/>
> >>        </exec>
> >>        <exec dir="${base.dir}" executable="ssh"  output="dir2.txt">
> >>        <arg line="-l michaeltaft jyotish.sourceforge.net"/>
> >>        </exec>
> >>        <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
> >>        <shellscript shell="bash.exe" >
> >>             <arg value="cd /home/groups/j/jy/jyotish/htdocs/"/>
> >>             <arg value="gunzip FJWeb.tar.gz"/>
> >>            <arg value="tar xf FJWeb.tar"/>
> >>            <arg value="rm FJWeb.tar"/>
> >>              ssh ${server} ./script.sh
> >>       </shellscript>
> >>
> >>I realize that this is a clumsy attempt, but it's the best I can do at
> >>my level of understanding. The web_zip and scp exec both work fine. The
> >>ssh exec starts to work but it only connects me to sourceforge and then
> >>gets hung up. Looking at the dir2.txt file I see the following comment:
> >>Pseudo-terminal will not be allocated because stdin is not a terminal.
> >>
> >>I'm not sure if that means it's not working at all, or if it just knows
> >>not to open the terminal. In any case that's as far as I've been able to
> >>get with this.
> >>
> >>Any help?
> >>
> >>peter reilly wrote:
> >>>Hi,
> >>>I have included the e-mail discussion on using shellscript and sshexec.
> >>>
> >>>shellscript can be received from CVS head of ant-contrib project
> >>>on sourceforge.
> >>>
> >>>http://sourceforge.net/projects/ant-contrib/
> >>>
> >>>sshexec can be received from CVS head of ant.
> >>>Peter.
> >>>
> >>>--------------------------//-------------------------------
> >>>
> >>>it is of course a lot better to use <sshexec/> than <shellscript/>
> >>>for this.
> >>>
> >>>Also my example contained an error, it should be
> >>><shellscript shell="sh"><![CDATA[
> >>>    ssh ${server} <<END
> >>>cd /tmp
> >>>ls -lrta
> >>>END
> >>>]]></shellscript>
> >>>
> >>>Peter.
> >>>
> >>>On Friday 21 March 2003 16:45, Anderson, Rob H - VSCM wrote:
> >>>>If you use the sshexec task you do not need to have an ssh client on
> >>>> your local machine. Obviously, the remote machine needs to be running
> >>>> sshd.
> >>>>
> >>>><sshexec host="somehost"
> >>>>     username="dude"
> >>>>     keyfile="${user.home}/.ssh/id_dsa"
> >>>>     passphrase="yo its a secret"
> >>>>     command="./remotesctipt.sh"/>
> >>>>
> >>>>If you want to execute an ant script on the remote machine you will
> >>>> need to install ant and the scripts on the remote machine. Then run
a
> >>>> task like the following
> >>>>
> >>>><sshexec host="somehost"
> >>>>     username="dude"
> >>>>     keyfile="${user.home}/.ssh/id_dsa"
> >>>>     passphrase="yo its a secret"
> >>>>     command="cd path/to/build/file ; ant targetname"/>
> >>>>
> >>>>I hope this helps.
> >>>>
> >>>>-Rob Anderson
> >>>>
> >>>>-----Original Message-----
> >>>>From: peter reilly [mailto:peter.reilly@corvil.com]
> >>>>Sent: Friday, March 21, 2003 3:25 AM
> >>>>To: Ant Users List
> >>>>Subject: Re: SSH in ANT?!?! (WAS: RE: process on a remote server via
an
> >>>>ANT ?????)
> >>>>
> >>>>
> >>>>I do not have windows at the moment so take what
> >>>>I am saying with a grain of salt.
> >>>>
> >>>>The question is not really an ant question. So
> >>>>test everything at the command line first.
> >>>>
> >>>>I assume that there is a ssh deamon/service running on
> >>>>the remote machine and there is a ssh command line
> >>>>utility in your exec path.
> >>>>
> >>>>If the sshd on the remote machine is a the cygwin sshd
> >>>>and you have cygwin installed correctly on both machines
> >>>>the script should work as is.
> >>>>
> >>>>If cygwin sshd is installed on the remote machine but the
> >>>>local machine does not have cygwin but does have another
> >>>>ssh client cli program that can run in a bat file one can do
> >>>>
> >>>><shellscript shell="cmd.exe" tmpsuffix=".bat">
> >>>>   <arg value="/c"/>
> >>>>    <arg value="call">
> >>>>     ssh ${server} ./script.sh
> >>>></shellscript>
> >>>>
> >>>>Other combinations you need to try yourself.
> >>>>
> >>>>Important to note that the ./script.sh is a file on the remote machine.
> >>>>
> >>>>To run a script defined in the ant build file do:
> >>>>
> >>>><shellscript shell="sh">
> >>>>   ssh ${server} <<END
> >>>>cd /tmp
> >>>>ls -lrta
> >>>>END
> >>>> </shellscript>
> >>>
> >>>On Sunday 23 March 2003 23:52, Michael Taft wrote:
> >>>>Hello -
> >>>>I've been using Ant in a hobbyist capacity for about a year now. I use
> >>>>it in jEdit to help me build my project.
> >>>>
> >>>>One thing I would like to do is automate the uploading of my website
> >>>>materials to sourceforge. Currently, I have a single ant task that tars
> >>>>them, gzips them, and then scps the whole lot to the home of my
> >>>>sourceforge site. That all works great.
> >>>>
> >>>>However, what I'd *really* like is to then be able to ssh into
> >>>>sourceforge, and unzip and untar the bundle. I created an executable
> >>>>task for ssh and was easily able to connect. But the next stage is
> >>>>confusing me a little bit. What I  need to do is execute three bash
> >>>>shell commands (cd blah blah, gunzip blah blah, and tar xf blah blah)
> >>>> on the remote server.
> >>>>
> >>>>Is there an executable task that does this?
> >>>>
> >>>>In looking at the list archive, I found something about a "shellscript"
> >>>>task that sounds right, but neither my copy of ant (both the very
> >>>> latest plugin for jEdit, and the other (also new) copy I have on my
> >>>> machine seem to implement this task.
> >>>>
> >>>>So, my questions are:
> >>>>
> >>>>1. Is "scriptshell" what I want?
> >>>>2. If not, what is.
> >>>>3. If so, where do I get it?
> >>>>
> >>>>Thanks in advance.
> >>>>M.
> >>>>
> >>>>
> >>>>---------------------------------------------------------------------
> >>>>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> >>>>For additional commands, e-mail: user-help@ant.apache.org
> >>>
> >>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> >>>For additional commands, e-mail: user-help@ant.apache.org
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> >>For additional commands, e-mail: user-help@ant.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message