我想在CentOS 7启动中运行交互式 Shell脚本,
我曾经尝试过post install
,/etc/rc.local
和crontab @reboot
,但没有一个与我合作
此外,我已经将它作为systemd进行了尝试,但也失败了。除了将其添加到登录之外,我需要任何方式来运行此脚本,我希望它在用户登录系统之前运行。有什么建议吗?
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
预先感谢