Bug 1273991 - write-append doesn't expand new lines properly when used in guestfish command line
write-append doesn't expand new lines properly when used in guestfish command...
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libguestfs (Show other bugs)
7.1
Unspecified Unspecified
unspecified Severity low
: rc
: ---
Assigned To: Richard W.M. Jones
Virtualization Bugs
:
Depends On:
Blocks: 1301891 1288337
  Show dependency treegraph
 
Reported: 2015-10-21 12:38 EDT by Martin Bukatovic
Modified: 2016-07-06 06:33 EDT (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2016-07-06 06:33:45 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Martin Bukatovic 2015-10-21 12:38:58 EDT
Description of problem
======================

When write-append command of guestfish is used in command line mode,
string '\n' is not properly expanded into new line in target file.

Version-Release number of selected component (if applicable)
============================================================

libguestfs-1.28.1-1.18.el7.x86_64
libguestfs-tools-c-1.28.1-1.18.el7.x86_64

How reproducible
================

100%

Steps to Reproduce
==================

1. On RHEL 7 host, find suitable image of virtual machine
2. Try to append few lines into /etc/hosts file on this image (vm.qcow2 in
   our case) via guestfish command line mode:

~~~
guestfish -a vm.qcow2 -i write-append /etc/hosts "10.0.0.1 foo.example.com\n10.0.0.2 bar.example.com\n"
~~~

3. Check the result via virt-cat:

~~~
virt-cat -a vm.qcow2 /etc/hosts
~~~

Actual results
==============

Occurences of string '\n' weren't expanded into new lines:

~~~
$ virt-cat -a vm.qcow2 /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.0.1 foo.example.com\n10.0.0.2 bar.example.com\n$
~~~

Expected results
================

Occurences of string '\n' are properly expanded:

~~~
$ virt-cat -a vm.qcow2 /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.0.0.1 foo.example.com
10.0.0.2 bar.example.com
$
~~~

Additional info
===============

Using interactive mode works as expected:

~~~
guestfish -a vm.qcow2 -i <<-EOF
	write-append /etc/hosts "10.0.0.1 foo.example.com\n10.0.0.2 bar.example.com\n"
EOF
~~~

Moreover we suggest to use this approach even for shell scripting in our
documentation already:

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Virtualization_Deployment_and_Administration_Guide/sect-Guest_virtual_machine_disk_access_with_offline_tools-The_guestfish_shell.html#sect-The_guestfish_shell-Shell_scripting_with_guestfish

On the other hand, man page of guestfish states:

~~~
SYNOPSIS
        guestfish [--options] [commands]
~~~

which makes me think that command line mode should work as well.
Comment 1 Richard W.M. Jones 2015-10-21 12:51:18 EDT
guestfish is working as intended.  Escape sequences are only
processed when we read commands from stdin.

You can use either of these two forms to get what you desire:

guestfish -a vm.qcow2 -i write-append /etc/hosts \
"10.0.0.1 foo.example.com
10.0.0.2 bar.example.com
"

guestfish -a vm.qcow2 -i <<EOF
write-append /etc/hosts "10.0.0.1 foo.example.com\n10.0.0.2 bar.example.com\n"
EOF

I'm pretty sure this bug is a duplicate, but I cannot find the
other bug right now ..
Comment 3 Richard W.M. Jones 2016-07-06 06:33:45 EDT
Closing per comment 1.  guestfish is working as intended.

Note You need to log in before you can comment on or make changes to this bug.