Hi I am sure the answer here is really easy but i am stuck! # mount | grep data | awk '{print$1,$2,$3}' gives me the info i require locally, however i need to execute this over about 1000 hosts so i run things remotely using ssh something like # MOUNTER=`ssh $i 'mount | grep data | awk '{print$1,$2,$3}''` however this fails as at the end of the line there are 2 ticks eg ' together - Can anyone offer me some syntax help please? thanks
On Oct 26, 2007, at 6:28, Tom Brown wrote:> I am sure the answer here is really easy but i am stuck!Getting the quoting right for remote commands in the shell is never an easy thing :-).> # mount | grep data | awk '{print$1,$2,$3}' > > gives me the info i require locally, however i need to execute this > over about 1000 hosts so i run things remotely using ssh something > like > > # MOUNTER=`ssh $i 'mount | grep data | awk '{print$1,$2,$3}''` > > however this fails as at the end of the line there are 2 ticks eg ' > together - > > Can anyone offer me some syntax help please?I can usually get this to work with some trial an error by doubling up quotes and using backslahes but it's a frustrating experience. Instead, I use a different technique: I put a script in a network accessible place (i.e., a common NFS mount) and then use ssh to execute that script. Alfred
Tom Brown wrote:> > # MOUNTER=`ssh $i 'mount | grep data | awk '{print$1,$2,$3}''` >How about # MOUNTER=`ssh $i "mount | grep data | awk '{print \$1,\$2,\$3}'"` Regards A.S
On Fri, Oct 26, 2007 at 11:28:37AM +0100, Tom Brown wrote:> Hi > > I am sure the answer here is really easy but i am stuck! > > # mount | grep data | awk '{print$1,$2,$3}' > > gives me the info i require locally, however i need to execute this over > about 1000 hosts so i run things remotely using ssh something like > > # MOUNTER=`ssh $i 'mount | grep data | awk '{print$1,$2,$3}''` > > however this fails as at the end of the line there are 2 ticks eg ' together > - > > Can anyone offer me some syntax help please?Well, you don't need to run the grep and awk on the other side: MOUNTER=`ssh $i mount | awk '/data/{print $1,$2,$3}'` But you can live without the call to mount, too: MOUNTER=`ssh $i awk "'/data/{print $1,$2,$3}'" /etc/mtab` -- lfr 0/0 -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available URL: <lists.centos.org/pipermail/centos/attachments/20071026/8e6515aa/attachment-0004.sig>
Hi all how can I have script to rename the following directory pattern from from dir-192.168.30.0 dir-192.168.30.144 dir-192.168.30.184 To: dir-10.0.30.0 dir-10.0.30.144 dir-10.0.30.184 thank you Send instant messages to your online friends uk.messenger.yahoo.com
Try: # find <parent dir> -type d -name dir-192.168.\* -exec mv \{\} `echo \{\} | sed 's/192\.168\./10\.0\./'` \; That should recursively rename all directories from one naming scheme to another. -Ross -----Original Message----- From: centos-bounces at centos.org <centos-bounces at centos.org> To: CentOS mailing list <centos at centos.org> Sent: Fri Nov 02 09:28:45 2007 Subject: Re: [CentOS] script help I run it but it has error. sed 's/^dir-192\.168/dir-10\.0/'` sed: read error on dir-192.168.0.31: Is a directory --- Toby Bluhm <tkb at MidwestInstruments.com> wrote:> Toby Bluhm wrote: > > adrian kok wrote: > >> Hi Phil > >> > >> thank you > >> > >> But I have several hundred those pattern > directories! > >> > >> I did think to cat those directories in a file > >> "olddir" > >> > >> eg: > >> > >> dir-192.168.30.0 dir-192.168.30.144 > dir-192.168.30.184 > >> ........................................ > >> > >> and sed 's/dir-192.168/dir-10.0/g' olddir > > newdir > >> > >> but i don't know how to move > >> rename the directories in olddir to newdir > >> > >> Thank you again > >> > >> > >> > > > > Assuming dir-192.168* are all in one directory > level, cd to that dir: > > > > for olddir in `ls -1 | grep dir-192.168` > > do > > newdir=`echo $olddir | sed > 's/^dir-192.168/dir-10.0/'` > > mv $olddir $newdir > > done > > > > > > That sed line should be: > 's/^dir-192\.168/dir-10\.0/'` > > > -- > Toby Bluhm > Midwest Instruments Inc. > 30825 Aurora Road Suite 100 > Solon Ohio 44139 > 440-424-2240 > > > _______________________________________________ > CentOS mailing list > CentOS at centos.org > lists.centos.org/mailman/listinfo/centos >Send instant messages to your online friends uk.messenger.yahoo.com _______________________________________________ CentOS mailing list CentOS at centos.org lists.centos.org/mailman/listinfo/centos ______________________________________________________________________ This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and may contain legally privileged and/or confidential information. If you are not the intended recipient of this e-mail, you are hereby notified that any dissemination, distribution or copying of this e-mail, and any attachments thereto, is strictly prohibited. If you have received this e-mail in error, please immediately notify the sender and permanently delete the original and any copy or printout thereof. -------------- next part -------------- An HTML attachment was scrubbed... URL: <lists.centos.org/pipermail/centos/attachments/20071102/b941bdb6/attachment.html>
Ross S. W. Walker wrote:> > Try: > > # find <parent dir> -type d -name dir-192.168.\* -exec mv \{\} `echo > \{\} | sed 's/192\.168\./10\.0\./'` \; > > That should recursively rename all directories from one naming scheme to > another.... except for the fact that the `echo \{\} ...` will be evaluated by the shell and not find, so this is the same as: find <parent dir> -type d -name dir-192.168.\* -exec mv \{\} \{\} \; Not very useful ;) Cheers, Michael