On Mon, Jan 20, 2014 at 08:54:17PM +0100, Olaf Hering
wrote:> Silly bash scripts have stuff like below to get things done, but equally
> silly guestfish scripts fail to add the required newline. Why is that?
>
> echo "$dev1 $mnt1 $fs $opts 1 2" >> /etc/fstab
> echo "$dev2 $mnt2 $fs $opts 1 2" >> /etc/fstab
>
> write-append /etc/fstab "$dev1 $mnt1 $fs $opts 1 2" : \
> write-append /etc/fstab "$dev2 $mnt2 $fs $opts 1 2" : \
>
>
> Even adding variants of \n does not help.
>
> Simple testcase:
>
> write /etc/fstab "#\n" : \
> write-append /etc/fstab '#1\n' : \
> write-append /etc/fstab '#2\\n' : \
> cat /etc/fstab : \
> quit
>
> ...
> libguestfs: trace: cat = "#\n#1\n#2\\n"
> #\n#1\n#2\\n
> libguestfs: trace: shutdown
> ...
>
> I guess using "sh" will be my workaround.
Yup, the parser in guestfish is ... informally specified.
In this case you can use guestfish commands instead of the
command line, ie:
guestfish -N fs -m /dev/sda1 <<EOF
write-append /fstab "123\n"
write-append /fstab "456\n"
write-append /fstab "789\n"
cat /fstab
EOF
Output:
123
456
789
Pino Toscano is looking at rewriting the parser to use a formally
specified language implemented using bison. It's not happened yet
however.
Have you considered using a real programming language, like Perl +
Sys::Guestfs, Python + guestfs etc.? Whenever I bump into the limits
of guestfish, I usually turn to Perl.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v