tags:

views:

79

answers:

3

I would like to have a shell script that copies some logs from a part of my system to the hudson workspace so I can archive them.

So right now I have

#!/bin/bash -ex
cp /directory/structure/*.log .

This is kind enough to be changed to

cp '/directory/structure/*.log' .

Which of course is not found since I don't have a file named *.log.

So how do I get this script to work?

EDIT So I left out the part that I was using sudo cp /path/*.log, because I didn't think that would matter. Of course it does and sudo is the issue not hudson.

+1  A: 

One simple answer would be to have the shell script in a separate file, and have hudson call that.

MatthieuF
That would be my last resort in this case. I'd like to be able to make changes to the script from off-site and our permissions are such that the webpage is much easier to get to then ssh'ing to the box.
Rob Spieldenner
If you're doing more than just the cp, then you could isolate just the cp into a separate script and then you retain flexibility
MatthieuF
A: 

Throwing it out there, but haven't had a chance to try it in Hudson (so I don't know how it gets quoted):

for f in /directory/structure/*.log ; do
    cp $f .
done

In my simple test in a bash shell, different quoting options produce either one or multiple invocations of the copy command (either with all matching files or one at a time), but they all manage to do the copy successfully.

Dave Bacher
Doesn't work. Hudson turns it into: for f in '/directory/structure/*.log' ; do
Rob Spieldenner
@Rob_Spieldenner OK. For me, $f now contains the quoted string and the shell performs the glob in the cp command.
Dave Bacher
+1  A: 
sudo bash -c "cp /directory/structure/*.log"
Rob Spieldenner

related questions