Home > Blockchain >  EOF operator in Shell not exiting
EOF operator in Shell not exiting

Time:12-20

I am trying to edit hadoop file on my guest machine using Vagrantfile. I am using cat. This edites the file but even EOF is considered as text and it has been inserted in the file /hadoop/conf/core-site.xml. EOF is not exiting and hence everything below is being considered as part of the text.

What change should I make on this code?

      if node.vm.hostname == "node1"
        node.vm.provision "shell", inline: <<-SHELL
        cat >/hadoop/conf/core-site.xml <<EOF
          <?xml version="1.0" encoding="UTF-8"?>
          <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
          <configuration>
            <property>
              <name>fs.default.name</name>
              <value>hdfs://localhost:8000</value>
            </property>
          </configuration>
          EOF          
        SHELL

      end

CodePudding user response:

Don't use inline shell for this kind of work. Mount actual files in a shared volume with the VM.

Otherwise, you're fighting both the ruby parser and the shell parser, and will certainly run into issues.

You could also use existing Ansible/Puppet/Chef Hadoop provisioning scripts with Vagrant rather than re-invent the wheel.

CodePudding user response:

Thanks @OneCricketer. Your suggestion helped. I created the xml file separately as core-site.xml.

<?xml version="1.0" encoding="UTF-8"?>
      <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
      <configuration>
        <property>
          <name>fs.default.name</name>
          <value>hdfs://localhost:8000</value>
        </property>
      </configuration>

Then, I created a bash file to create a symbolic link with this command

 sudo ln -sf /vagrant/hadoopscripts/core-site.xml /home/vagrant/hadoop/etc/hadoop/core-site.xml

Finally, I provisioned the bash which I named 'hadoopconfig.sh' from my Vagrantfile with this command.

config.vm.provision :shell, path: "shellscripts/hadoopconfig.sh" 

Thanks!

  • Related