Why does ksh script not get short hostname using initscript during boot whereas works if system is booted fine?

Solution Verified - Updated -

Issue

  • The following ksh script if executed a part of service, doesn't provide the output as expected.
[root@localhost ~]# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.3 (Maipo)

[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-514.10.2.el7.x86_64 #1 SMP Mon Feb 20 02:37:52 EST 2017 x86_64 x86_64 x86_64 GNU/Linux

[root@localhost ~]# cat /install/scripts/server_script.sh
#!/bin/sh
#-------------------------------------------------------------------------------
# chkconfig: 2345 99 01
# description: server_script.sh
#-------------------------------------------------------------------------------
/install/scripts/debughost.sh

[root@localhost ~]# ll /etc/init.d/server_script
lrwxrwxrwx. 1 root root 34 Jul 25 01:04 /etc/init.d/server_script -> /install/scripts/server_script.sh

[root@localhost ~]# chkconfig --list server_script

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

server_install  0:off   1:off   2:on    3:on    4:on    5:on    6:off

[root@localhost ~]# cat /install/scripts/debughost.sh
#!/bin/ksh

echo "start"
    BIN_PATH=/bin

echo "BIN_PATH is set to: $BIN_PATH"
    host=`${BIN_PATH}/hostname`
echo "host1:$host" >/tmp/debughost.log
    host=$(${BIN_PATH}/hostname)
echo "host2:$host" >>/tmp/debughost.log
echo "host3:$( ${BIN_PATH}/hostname)" >>/tmp/debughost.log
echo "host4:$( ${BIN_PATH}/hostname | sort)" >>/tmp/debughost.log
echo "host5:` ${BIN_PATH}/hostname`" >>/tmp/debughost.log
short_host=$(${BIN_PATH}/hostname |cut -d "." -f1)
echo "short_host:$short_host" >>/tmp/debughost.log
echo "short_host is set to: $short_host"
  • After reboot, the contents of the file log are
[root@localhost ~]# cat /tmp/debughost.log
host1:localhost.localdomain
host2:
host3:
host4:localhost.localdomain
host5:localhost.localdomain
short_host:localhost
  • Whereas it should have been as follows.
[root@localhost ~]# cat /tmp/debughost.log
host1:localhost.localdomain
host2:localhost.localdomain
host3:localhost.localdomain
host4:localhost.localdomain
host5:localhost.localdomain
short_host:localhost
  • Why ksh works unexpected during the boot?

Environment

  • Red Hat Enterprise Linux 7.3
  • ksh
  • selinux

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content