这个 sh 脚本有问题吗?

这个 sh 脚本有问题吗?

执行此 sh 脚本时遇到问题...我没有发现任何问题,有其他人发现我搞砸了什么吗?

echo "**************************************"
echo "***                                ***"
echo "***      Updated Please Read       ***"
echo "***                                ***"
echo "**************************************"
sleep 3
echo "Will updating this OS cause any issues with a control panel? [y|n]"
echo " Answer No for Cpanel, Direct Admin, Webmin, Plesk, VZ."
# CP = 'n'
# read CP

# if [[ ! `echo $CP | egrep '(y|yes|n|no)'` ]]; then
#
#        echo "Please answer with y or n:"
#        read CP
# fi

echo "Testing for SELinux..."
selinuxenabled

if [[ $? = 0 ]]; then

        echo "disabling SELinux..."
        sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
        setenforce 0
fi

echo "Initial time sync..."
ntpdate -b 204.123.2.72 > /dev/null 2>&1


        if [[ -f /etc/redhat-release ]]; then

                if [[ `egrep '(4\.[0-9]|\ 5\ |5\.[0-9]|\ 6\.[0-9])' /etc/redhat-release` ]]; then

                        CENT_VERSION=`cat /etc/redhat-release`
                else

                        echo "This version of CentOS is not compatible with this script."
                        echo "Please use the old instructions."
                        exit 1
                fi
        else

                echo "You are not running this script on CentOS."
                exit 2
        fi

        if [[ `echo $CENT_VERSION | grep 4\.[0-9]` ]]; then

                V=4

        elif [[ `echo $CENT_VERSION | egrep '(\ 5\ |5\.[0-9])'` ]]; then

                V=5
        fi


echo "Updating Resolvers..."

收到此错误:

sh harden.sh
: command not found
**************************************
***                                ***
***      Updated Please Read       ***
***                                ***
**************************************
sleep: invalid time interval `3\r'
Try `sleep --help' for more information.
Will updating this OS cause any issues with a control panel? [y|n]
 Answer No for Cpanel, Direct Admin, Webmin, Plesk, VZ.
: command not found
: command not found
Testing for SELinux...
: command not found selinuxenabled
: command not found

好像格式有些问题?

答案1

事实证明,这与 Windows 添加 \r 字符有关...有一个名为的实用程序dos2unix可以解决这个问题,但我只是自己在 Linux 中做了一些更改。

相关内容