[SLUG] coding

2010-11-18 Thread tony polkich
In --  grep $VAR afile.txt | sed 's/ ? / newdata/'  anotherfile.txt

what do I insert where the question mark is in sed? $VAR and variations haven't 
worked.




--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] coding

2010-11-18 Thread James Polley
Depends on what you're trying to accomplish.

However, there's not much point running through both grep and sed -
sed's featureset is (roughly) a super-set of grep:

andromeda:tmp polleyj$ cat afile.txt
This is a line
This is another
This is the third line
And this is a fourth.
andromeda:tmp polleyj$ grep line afile.txt | sed 's/third/second/'
This is a line
This is the second line
andromeda:tmp polleyj$ sed -e '/line/!d' -e 's/third/second/' afile.txt
This is a line
This is the second line
andromeda:tmp polleyj$

The various arguments and parameters passed to sed are described under
`man sed`.

You probably also want to read `man bash`, particularly the section
titled QUOTING.

andromeda:tmp polleyj$ VAR=astring
andromeda:tmp polleyj$ echo $VAR
astring
andromeda:tmp polleyj$ echo $VAR
astring
andromeda:tmp polleyj$ echo '$VAR'
$VAR

On Thu, Nov 18, 2010 at 10:38 AM, tony polkich basics_...@yahoo.com.au wrote:
 In --  grep $VAR afile.txt | sed 's/ ? / newdata/'  anotherfile.txt

 what do I insert where the question mark is in sed? $VAR and variations 
 haven't worked.




 --
 SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
 Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] coding

2010-11-18 Thread Norman Gaywood
On Thu, Nov 18, 2010 at 10:38 AM, tony polkich basics_...@yahoo.com.au wrote:
 In --  grep $VAR afile.txt | sed 's/ ? / newdata/'  anotherfile.txt

 what do I insert where the question mark is in sed? $VAR and variations 
 haven't worked.

Try changing the single quotes to double quotes. So:

grep $VAR afile.txt | sed s/$VAR/ newdata/  anotherfile.txt

Or, more simply:

sed s/$VAR/ newdata/ afile.txt  anotherfile.txt

Variables, like $VAR, are not expanded inside single quotes.

-- 
Norman Gaywood, Computer Systems Officer
University of New England, Armidale, NSW 2351, Australia

ngayw...@une.edu.auPhone: +61 (0)2 6773 3337
http://mcs.une.edu.au/~normFax:   +61 (0)2 6773 3312

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html
-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


[SLUG] Converting a Hard Drive to a Virtual Machine

2010-11-18 Thread david
I have an Ubuntu box running which I would like to be able to clone into 
a virtualbox VM.


I don't want to shut the hardware down, or play with it too much because 
it's a live server.


Is it possible to use MondoRescue or some other software to clone the 
server hard drive, preferably without shutting it down, and then create 
a virtual machine from the resulting image?


Thanks...

David
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] Converting a Hard Drive to a Virtual Machine

2010-11-18 Thread Daniel Pittman
david da...@kenpro.com.au writes:

 I have an Ubuntu box running which I would like to be able to clone into a
 virtualbox VM.  I don't want to shut the hardware down, or play with it too
 much because it's a live server.

 Is it possible to use MondoRescue or some other software to clone the server
 hard drive, preferably without shutting it down, and then create a virtual
 machine from the resulting image?

Not robustly, for cloning the raw disk, because you will end up with a really
messed up file system.  If you could stop file system access for a few hours
it would work, but that has ... probably the same issue. :)

What you *could* do is boot a LiveCD in the VM, and use rsync or something to
clone the files into the new machine.  Then, you can keep the block level
consistent and only risk file level oddities, which are much less nasty.

Daniel
-- 
✣ Daniel Pittman✉ dan...@rimspace.net☎ +61 401 155 707
   ♽ made with 100 percent post-consumer electrons
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html


Re: [SLUG] Converting a Hard Drive to a Virtual Machine

2010-11-18 Thread Peter Hardy
On Fri, 2010-11-19 at 15:25 +1100, david wrote:
 Is it possible to use MondoRescue or some other software to clone the 
 server hard drive, preferably without shutting it down, and then create 
 a virtual machine from the resulting image?

If you don't mind free-as-in-beer, we've used VMWare's vCenter Converter
to migrate a big chunk of our Windows and Linux machines to guests -
http://www.vmware.com/products/converter/ .

Before that, my quick, dirty but effective way to do it was:
- create the new virtual guest
- boot it using your favourite liveCD, partition drives and create
filesystems
- use tar and netcat to transfer the running system across the network:
  - on guest, mount the new root filesystem and run `nc -l -p 1717 | tar
-C /mountpoint xvf -
  - on old server, run something like `tar cf - --one-file-system / | nc
address_of_guest 1717`. You'll need to tune the tar command to make sure
you include all of the server's mounted filesystems.
- edit the new /etc/fstab on the guest as appropriate
- install a bootloader in the guest, usually by editing grub config
files in /boot/grub and running grub-install.

Note that I made no attempt to keep any services running on the old
server during this process. So all but the bare minimum was shut down,
and there weren't any critical files being written to. On a real running
system, you're more than likely going to end up with some files in an
inconsistent state doing this if the old server is trying to write to
them.

-- 
Pete

-- 
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html