PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Feeding two consecutive commands using xargs
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Feeding two consecutive commands using xargs

Réponse
 
LinkBack Outils de la discussion
Vieux 22/05/2007, 13h08   #1
Mark Hobley
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Feeding two consecutive commands using xargs

I am using a borne compatible shell, and I want to like to try and chain a
series of commands together using a one-liner to achieve the following:

I have a command "modprobe", which provides a list of modules:

/lib/modules/2.6.18-4-486/kernel/sound/oss/uart6850.ko
/lib/modules/2.6.18-4-486/kernel/sound/oss/uart401.ko
/lib/modules/2.6.18-4-486/kernel/sound/oss/trix.ko

(and squillions more besides)

I now want to strip the full path and extention, which I have achieved as
follows:

/sbin/modprobe -l|xargs -l1 -I '{}' basename {} .ko

This produces:

uart6850
uart401
trix

Now I want to echo the name and modinfo -L. This is where I am stuck. I need
to feed two commands. I want to output a filename, a space and then a
description for each module.

The following gives me a list of descriptions, but no filename:

/sbin/modprobe -l|xargs -l1 -I '{}' basename {} .ko| xargs -l1 -I '{}'
/sbin/modinfo -F description {}

I want to modify this as follows, but I don't know the syntax:

/sbin/modprobe -l|xargs -l1 -I '{} basename {} .ko| xargs -l1 -I '{}' { echo
{}; echo ' '; /sbin/modinfo -F description {} }

I am trying three commands in a script as follows:

{ echo {}; echo ' '; /sbin/modinfo -F description {} }

I assumed the { and } would make a block of code, somehow.

Presumably, I could eliminate one of the xargs calls somehow.

Thanks in advance to anyone who can .

Mark.

--
Mark Hobley
393 Quinton Road West
QUINTON
Birmingham
B32 1QE

Email: markhobley at hotpop dot donottypethisbit com

http://markhobley.yi.org/

  Réponse avec citation
Vieux 22/05/2007, 13h52   #2
Icarus Sparry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Feeding two consecutive commands using xargs

On Tue, 22 May 2007 12:08:03 +0000, Mark Hobley wrote:

> I am using a borne compatible shell, and I want to like to try and chain
> a series of commands together using a one-liner to achieve the
> following:
>
> I have a command "modprobe", which provides a list of modules:
>
> /lib/modules/2.6.18-4-486/kernel/sound/oss/uart6850.ko
> /lib/modules/2.6.18-4-486/kernel/sound/oss/uart401.ko
> /lib/modules/2.6.18-4-486/kernel/sound/oss/trix.ko
>
> (and squillions more besides)
>
> I now want to strip the full path and extention, which I have achieved
> as follows:
>
> /sbin/modprobe -l|xargs -l1 -I '{}' basename {} .ko
>
> This produces:
>
> uart6850
> uart401
> trix
>
> Now I want to echo the name and modinfo -L. This is where I am stuck. I
> need to feed two commands. I want to output a filename, a space and then
> a description for each module.
>
> The following gives me a list of descriptions, but no filename:
>
> /sbin/modprobe -l|xargs -l1 -I '{}' basename {} .ko| xargs -l1 -I '{}'
> /sbin/modinfo -F description {}
>
> I want to modify this as follows, but I don't know the syntax:
>
> /sbin/modprobe -l|xargs -l1 -I '{} basename {} .ko| xargs -l1 -I '{}' {
> echo {}; echo ' '; /sbin/modinfo -F description {} }
>
> I am trying three commands in a script as follows:
>
> { echo {}; echo ' '; /sbin/modinfo -F description {} }
>
> I assumed the { and } would make a block of code, somehow.


There is not often a need to uses "xargs -1", it can frequently be
replaced
with a shell loop.

/sbin/modprobe -l | while read name ; do
printf '%16s ' $(basename $name .ko );
/sbin/modinfo -F description $name ; done

This is written out over 3 lines, but if you remove all the newline
characters it will become a one-liner.

If you wanted to use xargs, then construct the command as a string
and give it to sh -c, e.g. something like

modprobe | xargs -1 basename | xargs -1 sh -c "echo {}; modinfo {}"
  Réponse avec citation
Vieux 22/05/2007, 16h03   #3
Jean-Rene David
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Feeding two consecutive commands using xargs

* Mark Hobley [2007.05.22 12:08]:
> I have a command "modprobe", which provides a list of modules:
>
> /lib/modules/2.6.18-4-486/kernel/sound/oss/uart6850.ko
> /lib/modules/2.6.18-4-486/kernel/sound/oss/uart401.ko
> /lib/modules/2.6.18-4-486/kernel/sound/oss/trix.ko
>
> (and squillions more besides)

[...]
> Now I want to echo the name and modinfo -L.

[...]

It's usually clearer to include an example of the output you
want rather than describing it in words only. This does what
I think you want.

IFS='
'
for module in $(modprobe -l)
do
paste <(basename "$module" .ko) <(modinfo -F description "$module")
done

As for being a one-liner, you can always make it that way
but I don't see the advantage.

--
JR
  Réponse avec citation
Vieux 22/05/2007, 16h13   #4
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Feeding two consecutive commands using xargs

2007-05-22, 12:08(+00), Mark Hobley:
> I am using a borne compatible shell, and I want to like to try and chain a
> series of commands together using a one-liner to achieve the following:
>
> I have a command "modprobe", which provides a list of modules:
>
> /lib/modules/2.6.18-4-486/kernel/sound/oss/uart6850.ko
> /lib/modules/2.6.18-4-486/kernel/sound/oss/uart401.ko
> /lib/modules/2.6.18-4-486/kernel/sound/oss/trix.ko
>
> (and squillions more besides)
>
> I now want to strip the full path and extention, which I have achieved as
> follows:
>
> /sbin/modprobe -l|xargs -l1 -I '{}' basename {} .ko
>
> This produces:
>
> uart6850
> uart401
> trix
>
> Now I want to echo the name and modinfo -L. This is where I am stuck. I need
> to feed two commands. I want to output a filename, a space and then a
> description for each module.
>
> The following gives me a list of descriptions, but no filename:
>
> /sbin/modprobe -l|xargs -l1 -I '{}' basename {} .ko| xargs -l1 -I '{}'
> /sbin/modinfo -F description {}

[...]

modprobe -l | awk -F/ '
{print $NF; system("modinfo -F description " $0)}'

--
Stéphane
  Réponse avec citation
Vieux 22/05/2007, 20h16   #5
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Feeding two consecutive commands using xargs

On 2007-05-22, Stephane CHAZELAS wrote:
> 2007-05-22, 12:08(+00), Mark Hobley:
>> I am using a borne compatible shell, and I want to like to try and chain a
>> series of commands together using a one-liner to achieve the following:
>>
>> I have a command "modprobe", which provides a list of modules:
>>
>> /lib/modules/2.6.18-4-486/kernel/sound/oss/uart6850.ko
>> /lib/modules/2.6.18-4-486/kernel/sound/oss/uart401.ko
>> /lib/modules/2.6.18-4-486/kernel/sound/oss/trix.ko
>>
>> (and squillions more besides)
>>
>> I now want to strip the full path and extention, which I have achieved as
>> follows:
>>
>> /sbin/modprobe -l|xargs -l1 -I '{}' basename {} .ko
>>
>> This produces:
>>
>> uart6850
>> uart401
>> trix
>>
>> Now I want to echo the name and modinfo -L. This is where I am stuck. I need
>> to feed two commands. I want to output a filename, a space and then a
>> description for each module.
>>
>> The following gives me a list of descriptions, but no filename:
>>
>> /sbin/modprobe -l|xargs -l1 -I '{}' basename {} .ko| xargs -l1 -I '{}'
>> /sbin/modinfo -F description {}

> [...]
>
> modprobe -l | awk -F/ '
> {print $NF; system("modinfo -F description " $0)}'


Better yet, since calling system() for every line is ridiculously
inefficient:

modprobe -l | while IFS= read mod
do
printf "%s\n" "${mod##*/}"
modinfo -F description "$mod"
done



--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 22/05/2007, 20h40   #6
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Feeding two consecutive commands using xargs

2007-05-22, 15:16(-04), Chris F.A. Johnson:
[...]
>> modprobe -l | awk -F/ '
>> {print $NF; system("modinfo -F description " $0)}'

>
> Better yet, since calling system() for every line is ridiculously
> inefficient:
>
> modprobe -l | while IFS= read mod
> do
> printf "%s\n" "${mod##*/}"
> modinfo -F description "$mod"
> done

[...]

you're calling read, printf and modinfo for every line. There's
no guarantee it will be more efficient, though I'd agree with
most nowadays implementations of sh (where read and printf are
built in), it is probably true.

Why you'd ask "read" to do some backslash processing is not clear
to me though.

--
Stéphane
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h55.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13664 seconds with 14 queries