自动化脚本不起作用

时间:2016-08-15 12:15:31

标签: mysql bash

我已经制作了以下剧本,但它并不是从一开始就开始的。也没有按预期运作。请有人帮助找出问题,以便同样可行。谢谢......一些输出低于

if [[ "$(whoami)" != 'root' ]]; then
        echo "You need to be logged in as root to proceed";
        exit 1
fi


VERSION=$(awk '{print $3}' /etc/redhat-release|cut -d "." -f1)

#if (( "$VERSION" < 7 ))
if [ "$VERSION" -lt 7 ];then

    echo "PHP Version 5.4 need to be installed separately"

else
    echo "PHP Version 5.4 will be installed by default"

fi

TIMEZONE=$(date |awk '{print $5}')
#if [[`` = IST]];then
if [[ $"TIMEZONE" -eq IST ]];then
    echo "Server is already configured with IST Time Zone"
else
    rm -f /etc/localtime
    cp -v /usr/share/zoneinfo/Asia/Kolkata  /etc/localtime
fi

#MDB=$(ls -l /etc/yum.repos.d/|awk '{print $9}'|grep MariaDB.repo)
MDB="/etc/yum.repos.d/MariaDB.repo"
if [[ -f "$MDB" ]]
then
    echo "Repo already exists"
else
    touch "$MDB"

cat << EOF >> /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB-10.1.9
baseurl=https://downloads.mariadb.com/files/MariaDB/mariadb-10.1.9/yum/centos/$(awk '{print $3}' /etc/redhat-release|cut -d"." -f1,2)/$(uname -i)/
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
enabled=1
exclude=MariaDB-connect-engine.x86_64,MariaDB-test.x86_64
EOF
fi
sleep 2

if [[ $(pgrep yum | wc -l) != 1 ]];
then
    pkill -9 yum
sleep 1
else
    yum clean all
    yum install epel-release httpd httpd-devel -y
sleep 1
    yum install php php-cli php-common php-devel php-pear php-gd php-mbstring php-mysql php-xml php-odbc php-pdo php-bcmath php-xmlrpc -y
    yum install MariaDB* -y --nogpgcheck
fi
    echo "Current PHP Version is $(php -v|head -1|cut -d "." -f1-2)"
sleep 1

NOW=$(date +"%d-%m-%y_%H:%M")
if [ "$VERSION" -lt 7 ];then

    yum install centos-release-SCL -y
    yum install php54 php54-php-cli php54-php-common php54-php-devel php54-php-pear php54-php-gd php54-php-mbstring php54-php-mysql php54-php-xml php54-php-odbc php54-php-pdo php54-php-bcmath php54-php-xmlrpc -y
sleep 2
    echo "Current PHP Version is $(php -v|head -1|cut -d " " -f1-2)"
    source /opt/rh/php54/enable
    echo "Updated PHP Version is $(php -v|head -1|cut -d " " -f1-2)"
    echo "Now Commenting line 'LoadModule php5_module modules/libphp5.so' in '/etc/httpd/conf.d/php.conf' ...."
    sed -i '6 s/^/#/' /etc/httpd/conf.d/php.conf
fi
    cp /etc/php.ini /etc/php.ini_bak_"$NOW"
    sed -i 's/;date.timezone =/date.timezone = Asia\/Calcutta/g' /etc/php.ini
#   sed -i '947i date.timezone = Asia/Calcutta' /etc/php.ini
sleep 1

echo "Now Starting HTTPD Service..."
    service httpd start
    service httpd restart
echo "Now Starting MAIL Service..."
    service sendmail start
    service sendmail restart
echo "Now Starting MYSQL Service..."
    service mysql start
    service mysql restart
sleep 1

SQLDB_ROOT_PWD="Test_DB"

if [[ $(pgrep mysql | wc -l) != 1 ]];
then
    service mysql start;
fi

mysql_secure_installation <<EOF

y
$SQLDB_ROOT_PWD
$SQLDB_ROOT_PWD
y
n
y
y
EOF
sleep 2

输出

 PHP Version 5.4 need to be installed separately
Server is already configured with IST Time Zone
Repo already exists
Current PHP Version is 
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
Package centos-release-scl-rh-2-3.el6.centos.noarch already installed and latest version
Nothing to do
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: centos.excellmedia.net
 * extras: centos.excellmedia.net
 * updates: centos.excellmedia.net
Package php54-2.0-1.el6.x86_64 already installed and latest version
Package php54-php-cli-5.4.40-3.el6.x86_64 already installed and latest version
Package php54-php-common-5.4.40-3.el6.x86_64 already installed and latest version
Package php54-php-devel-5.4.40-3.el6.x86_64 already installed and latest version
Package 1:php54-php-pear-1.9.4-10.sc1.el6.noarch already installed and latest version
Package php54-php-gd-5.4.40-3.el6.x86_64 already installed and latest version
Package php54-php-mbstring-5.4.40-3.el6.x86_64 already installed and latest version
Package php54-php-mysqlnd-5.4.40-3.el6.x86_64 already installed and latest version
Package php54-php-xml-5.4.40-3.el6.x86_64 already installed and latest version
Package php54-php-odbc-5.4.40-3.el6.x86_64 already installed and latest version
Package php54-php-pdo-5.4.40-3.el6.x86_64 already installed and latest version
Package php54-php-bcmath-5.4.40-3.el6.x86_64 already installed and latest version
Package php54-php-xmlrpc-5.4.40-3.el6.x86_64 already installed and latest version
Nothing to do
Current PHP Version is 
Updated PHP Version is PHP 5.4.40
Now Commenting line 'LoadModule php5_module modules/libphp5.so' in '/etc/httpd/conf.d/php.conf' ....
Now Starting HTTPD Service...
Starting httpd: 
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
Now Starting MAIL Service...
Now Starting MYSQL Service...

它没有以

开头
  1. 检查当前登录的用户
  2. 然后设置时区
  3. DB repo creation
  4. 其他套餐安装..

0 个答案:

没有答案