1

I want to run interactive shell script in CentOS 7 boot, I have tried to post install, /etc/rc.local and crontab @reboot but none of them worked with me

Also, I have tried it as a systemd but it failed also. I need any way to run this script except adding it to login, I want it to run before user logs in into system. Any suggestions?

hostname=""
ip=""
netmask=""
gw=""
opts=""
answer="n"
device="eth0"
hwaddr=`ifconfig $device | grep -i hwaddr | sed -e 's#^.*hwaddr[[:space:]]*##I'`
dns1="205.171.2.65"
dns2="205.171.3.65"

curTTY=`/dev/tty`
exec < $curTTY > $curTTY 2> $curTTY
clear

while [ x"$answer" != "xy" ] && [ x"$answer" != "xY" ] ; do
        echo -n "enter hostname: "; read hostname
        echo -n "enter ip: "; read ip
        echo -n "enter netmask: "; read netmask
        echo -n "enter default gw: "; read gw
        echo -n "hard set '100baseTX full-dulplex' [y/n] " ; read opts
        echo

        echo You entered:
        echo -e "\thostname: $hostname"
        echo -e "\tip: $ip"
        echo -e "\tnetmask: $netmask"
        echo -e "\tdefault gw: $gw"
        echo -e "\tset 100baseTX full-duplex: $opts"
        echo -n "Is this correct? [y/n] "; read answer
done

if [ x"$opts" = "xy" ] ; then
        opts="speed 100 duplex full autoneg off"
else
        opts=""
fi

sed -i -e 's#^\(HOSTNAME=\).*$#\1'"$hostname"'#' /etc/sysconfig/network
echo GATEWAY=$gw >> /etc/sysconfig/network

echo DEVICE=$device > $scrFile
echo BOOTPROTO=static >> $scrFile
echo ONBOOT=yes >> $scrFile
echo NM_CONTROLLED=no >> $scrFile
echo HWADDR=$hwaddr >> $scrFile
echo IPADDR=$ip >> $scrFile
echo NETMASK=$netmask >> $scrFile
echo USERCTL=no >> $scrFile
echo DNS1=$dns1 >> $scrFile
echo DNS2=$dns2 >> $scrFile

if [ "x$opts" != "x" ] ; then
        echo 'ETHTOOL_OPTS="'"$opts"'"' >> $scrFile
fi

Thanks in advance

barbsan
  • 3,418
  • 11
  • 21
  • 28
  • None of `rc.local`, `cron` or `systemd` will allocate a tty for interaction. You could use something like `openvt`. There's [an answer already on superuser for this](https://superuser.com/questions/584931/howto-start-an-interactive-script-at-ubuntu-startup). – Anya Shenanigans Dec 04 '18 at 09:08
  • Thanks a million, It works fine with me, Can I redirect output to dialog or is openvt allow me to redirect out put to dialog? – user2039058 Dec 04 '18 at 10:03
  • I don't quite understand what you're asking - are you trying to get the interaction logged somewhere into a file? – Anya Shenanigans Dec 04 '18 at 17:03
  • Thanks Petesh, I want to run this script in startup with any basic level graphical user interface like dialg, Is it possible ? – user2039058 Dec 05 '18 at 09:07
  • `openvt` would only offer you a simple command-line interface. I'm not familiar with `dialg`. – Anya Shenanigans Dec 05 '18 at 10:32

0 Answers0