Trying to append a text at the end of the hosts file but not working through userdata .
Service_start.sh script will execute certain commands and also a shell script (hostnames.sh) once server started. every script is working but not this hostnames.sh and in the output log it is showing as success. I can’t see IP and hostname in the /etc/hosts
If I run it manually then it is working
Service_start.sh file contains
#!/bin/bash
#script to udate hostnames in hosts file
ip=`facter testip`
hostname=`facter testhostname`
sudo /bin/bash /opt/resources/hostnames.sh >> /opt/test.log
and hostnames.sh file conatains
#!/bin/bash
#script to udate hostnames in hosts file
ip=`facter testip`
hostname=`facter testhostname`
echo " " >> /etc/hosts
if [ $? -eq 0 ]; then
echo SUCCESS
else
echo FAIL
fi
echo "$ip $hostname" >> /etc/hosts
if [ $? -eq 0 ]; then
echo SUCCESS
else
echo FAIL
fi