-1

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
jordanm
  • 33,009
  • 7
  • 61
  • 76
Sathya
  • 1
  • 1

1 Answers1

0

You just need to change the ` to "

ip="facter testip"
hostname="facter testhostname"
micah
  • 838
  • 7
  • 21
  • Above script is working fine if I run it manaully so no isses with the scrpit – Sathya Aug 17 '22 at 14:36
  • oh sorry, so you're using the `facter` command? I'm unfamiliar with that command and thought you were just making strings. – micah Aug 17 '22 at 14:43