bedtime question : xargs
vu pham
vu at sivell.com
Thu Apr 23 06:55:22 PDT 2009
vu pham wrote:
> Roger Oberholtzer wrote:
>> On Thu, 2009-04-23 at 07:38 -0500, vu pham wrote:
>>> Roger Oberholtzer wrote:
>>>> On Wed, 2009-04-22 at 22:59 -0500, Vu Pham wrote:
>>>>> Using xargs, how can I pipe the output ( of some command ) as the
>>>>> *first* parameter of some other command ?
>>>>>
>>>>> Here is my problem: I have various rpm files in a directory tree. I
>>>>> want to copy all of these files to a remote server using scp. What
>>>>> I am thinking is
>>>>>
>>>>> [oliver at xen2vm4 redhat]$ find . -name "*.rpm"
>>>>> ./SRPMS/hello-1.0.0-2.src.rpm
>>>>> ./SRPMS/hello-1.0.0-1.src.rpm
>>>>> ./RPMS/i686/hello-1.0.0-2.i686.rpm
>>>>> ./RPMS/i686/hello-1.0.0-1.i686.rpm
>>>>>
>>>>>
>>>>> # find . -name "*.rpm" | xargs scp ??? root at remoteserver:
>>>> perhaps
>>>>
>>>> find . -name \*.rpm | xargs scp {} root at remoteserver:
>>>>
>>>>
>>> Thanks, Roger, but I got the below error:
>>>
>>> [oliver at xen2vm4 ~]$ find . -name \*.rpm | xargs scp {} root at xen2vm1:
>>> ./redhat/RPMS/i686/hello-1.0.0-1.i686.rpm: Not a directory
>>
>> I know you solved it, but I am curious what the error was. A chance to
>> learn something.
>>
>> What do you get with:
>>
>> find . -name \*.rpm | xargs echo scp {} root at xen2vm1:
>>
>> Does the command look correct? Do you (GF) have any spaces in the names?
>> It didn't look like such a tree. xargs also takes an argument to tell
>> how big a buffer to use. But of course, your shell could cause problems
>> if the buffer is too big.
>>
>> Having said all this, I, like David in this thread, use -exec. I seldom
>> use xargs. But I wanted to answer your question.
>>
>
> Roger,
>
> I appreciate your reply and I also want to know why using xargs /scp
> does not work.
>
> Here is the output
> [root at xen2vm1 ~]# find . -name \*.rpm | xargs echo scp {} root at xen2vm1:
> scp {} root at xen2vm1: ./hello-1.0.0-2.src.rpm ./hello-1.0.0-2.i686.rpm
> ./hello-1.0.0-1.src.rpm ./hello-1.0.0-1.i686.rpm
>
> [root at xen2vm1 ~]# find . -name \*.rpm | xargs scp {} root at xen2vm1:
> ./hello-1.0.0-1.i686.rpm: Not a directory
> [root at xen2vm1 ~]#
>
Roger, maybe this is what we want
[root at xen2vm1 ~]# find . -name \*.rpm | xargs -I {} scp {} root at xen2vm1:
root at xen2vm1's password:
hello-1.0.0-2.src.rpm
100% 3056 3.0KB/s
00:00
root at xen2vm1's password:
hello-1.0.0-2.i686.rpm
100% 6473 6.3KB/s
00:00
root at xen2vm1's password:
hello-1.0.0-1.src.rpm
100% 3058 3.0KB/s
00:00
root at xen2vm1's password:
hello-1.0.0-1.i686.rpm
100% 6476 6.3KB/s
00:00
[root at xen2vm1 ~]#
Vu
More information about the Linux-users
mailing list