美文网首页
编写 Shell 脚本,实现环境移植(从 Windows 到 C

编写 Shell 脚本,实现环境移植(从 Windows 到 C

作者: 嫩牛_软件测试_笔记 | 来源:发表于2018-09-25 12:24 被阅读0次

说明:

项目以 ranzhi 为例(自己随便百度搜索 ranzhi 开源代码一大堆,可别告诉我你不会使用度娘喔)

操作步骤:

1、ranzhi 是一个 Web 项目,可以先将 ranzhi 项目部署到 Windows 系统上(可以推荐用个继承的工具,如 XAMPP,同样可以找度娘提供给你的);

2、可以安装个虚拟机(如 VMWare),然后在虚拟机上安装个 CentOS(如我这里安装的是 CentOS6.8 版本),默认 CentOS 上是安装好了 Apache( httpd 服务,直接开启就可以使用了);MySQL版本是 5.1,我们这里是要将 5.1 版本卸载掉先,再安装 5.7 版本;PHP 默认是没有安装的,我们需要全新安装个PHP。

【特别说明:rpm packages 'mysql57-community-release-el6-11.noarch.rpm'(for Mysql),'epel-release-6-8.noarch.rpm'(for PHP),'remi-release-6.rpm'(for PHP) 都是自己可以从 MySQL 和 PHP 官网下载】

如下,就是我写的环境移植Shell脚本(如取名为 Win_CentOS.sh),将 ranzhi 项目从 Windows 移植到 CentOS 环境

(自己提前将 Windows 环境下的 ranzhi 项目打包成 zip 压缩包(如ranzhi.zip),以及将 ranzhi 数据库导出为 .sql 脚本(如 ranzhi.sql)。)

(建立1个目录'php_mysql',将3个rpm packages( 'mysql57-community-release-el6-11.noarch.rpm','epel-release-6-8.noarch.rpm','remi-release-6.rpm')放到'php_mysql'目录下,与ranzhi.zip, ranzhi.sql, Win_CentOS.sh 一起上传到CentOS的 /var/www/html 路径下)

以下为详细的Shell脚本 Win_CentOS.sh 内容:


#!/bin/bash
##Author: Jet Liu
##QQ: 406834061
##Mobile/WeiXin: 13807083044
##Build test environment automatically!!!
Start_Time=`date +%s`
#根据半径,打印菱形
LingXing(){
r=6
for((y=0; y<=2*r; y++))
do
for((x=0; x<=2*r; x++))
do
#if ((y==-x+r || y==-x+3*r || y==x+r || y==x-r))  空心
if ((y>=-x+r && y<=-x+3*r && y<=x+r && y>=x-r))   #实心
then
echo -n "*"
else
echo -n " "
fi
done
echo ""
done
}
# call the function in shell
LingXing
#Set the colors of font
RED='\033[5;31m'
SHAN_GREEN='\033[1;5;41;32m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo -e "${GREEN}>>>Begin with LingXing...${NC}"
echo -e "${GREEN}>>>Project ranzhi,moving from Windows to CentOS6.8 <<<${NC}"
echo -e "${GREEN}>>>Checking the necessary file 'ranzhi.zip','ranzhi.sql',the necessary directory 'php_mysql' if existed in the directory '/var/www/html'? check the 3 installing of rpm packages 'mysql57-community-release-el6-11.noarch.rpm'(for Mysql),'epel-release-6-8.noarch.rpm'(for PHP),'remi-release-6.rpm'(for PHP) are all in the directory 'php_mysql'?<<<${NC}"
if [ -f "/var/www/html/ranzhi.zip" -a -f "/var/www/html/ranzhi.sql" -a -f "/var/www/html/php_mysql/mysql57-community-release-el6-11.noarch.rpm" -a -f "/var/www/html/php_mysql/epel-release-6-8.noarch.rpm" -a -f "/var/www/html/php_mysql/remi-release-6.rpm" ];then
echo -e "${GREEN}>>>Good,all the necessary files exist!!!<<<${NC}"
else
echo -e "${RED}>>>Attentions:some necessary files not exist,pls check!!!<<<${NC}"
fi
echo -e "${GREEN}>>>Starting apache...<<<${NC}"
Httpd_Start=`service httpd start`
echo -e "${GREEN}>>>Query apache service status...<<<${NC}"
Httpd_Status_Running=`service httpd status | grep running | wc -l`
if test $Httpd_Status_Running = 1
then
echo -e "${GREEN}>>>Apache is running...<<<${NC}"
else
echo -e "${RED}>>>Apache start failed!!!<<<${NC}"
fi
echo -e "${GREEN}>>>Checking the installing of MySQL in the system...<<<${NC}"
mysql51_1=`yum list installed | grep mysql | grep 5.1 | wc -l`
if [ ${mysql51_1} -ne 0 ];then
echo -e "${GREEN}>>>Mysql5.1 is installed in the system.<<<${NC}"
echo -e "${GREEN}>>>Removing Mysql5.1...<<<${NC}"
echo -e "${YELLOW}>>>Will cost few minutes, pls wait ...<<<${NC}"
Remove_Old_Mysql=$(yum remove mysql* -y)
mysql51_2=`yum list installed | grep mysql | grep 5.1 | wc -l`
if [ ${mysql51_2} -eq 0 ];then
echo -e "${GREEN}>>>Mysql5.1 removed OK!!!<<<${NC}"
fi
echo -e "${GREEN}>>>Removing the old mysql data of Mysql5.1<<<${NC}"
rm_mysql_data=`rm -rf /var/lib/mysql/`
if [ ! -d '/var/lib/mysql' ];then
echo -e "${GREEN}>>>The old mysql data of Mysql5.1 has been removed ok just now!<<<${NC}"
else
echo -e "${RED}>>>The old mysql data of Mysql5.1 has not been removed ok just now!<<<${NC}"
fi
fi
mysql57_1=`yum list installed | grep mysql | grep 5.7 | wc -l`
if [ ${mysql57_1} -eq 0 ];then
echo -e "${YELLOW}>>>Mysql5.7 has not been installed in this system,will install MySQL5.7...<<<${NC}"
echo -e "${GREEN}>>>Installing Mysql5.7...<<<${NC}"
rpm_mysql_community=`rpm -Uvh /var/www/html/php_mysql/mysql57-community-release-el6-11.noarch.rpm --force --nodeps`
echo -e "${GREEN}>>>Installing MySQL-Communitiy-Server...<<<${NC}"
echo -e "${GREEN}>>>Will cost some minutes,pls wait...<<<${NC}"
yum_install_mysql_community=$(yum install mysql-community-server -y)
mysql57_2=`yum list installed | grep mysql | grep 5.7 | wc -l`
if [ ${mysql57_2} -ne 0 ];then
echo -e "${GREEN}>>>Mysql5.7 has been installed successful,pls note...<<<${NC}"
fi
else
echo -e "${YELLOW}>>>Mysql5.7 has been installed before,no need to reinstall mysql5.7 now...<<<${NC}"
fi
mysql51_3=`yum list installed | grep mysql | grep 5.1 | wc -l`
mysql57_3=`yum list installed | grep mysql | grep 5.7 | wc -l`
if [ ${mysql51_3} -eq 0 -a ${mysql57_3} -eq 0 ];then
echo -e "Mysql5.1 & 5.7 are both not installed!"
fi
echo -e "${GREEN}>>>First to start mysql...<<<${NC}"
Mysql_Start_1=`service mysqld start`
echo -e "${GREEN}>>>Second to start mysql...<<<${NC}"
Mysql_Start_2=`service mysqld start`
Mysql_Temp_Check=`mysql -uroot -pDj.123456 -e "show databases" | grep mysql | wc -l`
if [ $Mysql_Temp_Check -eq 1 ];then
echo -e "${YELLOW}>>>The temp pwd of mysql has been changed to 'Dj.123456',so no need to alter the temp pwd for mysql again...<<<${NC}"
else
echo -e "${GREEN}>>>Will alter mysql5.7 temp password...<<<${NC}"
defaultmysqlpwd=`grep 'A temporary password' /var/log/mysqld.log | awk -F"root@localhost: " '{ print $2}' | tail -1`
#defaultmysqlpwd=`grep 'temporary password' /var/log/mysqld.log | cut -d ":" -f 4 | tail -1 | cut -c 2-`
mysql -uroot -p$defaultmysqlpwd --connect-expired-password <<EOF
alter user 'root'@'localhost' identified by 'Dj.123456';
EOF
Mysql_Restart=`service mysqld restart`
Mysql_Temp_Check_2=`mysql -uroot -pDj.123456 -e "show databases" | grep mysql | wc -l`
if [ ${Mysql_Temp_Check_2} -eq 1 ];then
echo -e "${GREEN}>>>Mysql5.7 temp pwd of user 'root' has been changed to 'Dj.123456'!!!<<<${NC}"
fi
fi
echo -e "${GREEN}>>>Checking the mysql user 'tester'@'%' if exist,and check the password of 'tester'@'%' if setted to 'Dj.123456'...<<<${NC}"
mysql='mysql -uroot -pDj.123456'
Tester_Check=`mysql -uroot -pDj.123456 -e "SELECT COUNT(*) FROM mysql.user a WHERE USER = 'tester' and HOST = '%'" | tail -1`
if [ $Tester_Check -eq 1 ];then
echo -e "${YELLOW}>>>The user 'tester'@'%' of mysql exsited<<<${NC}"
echo -e "${GREEN}>>>Reset the password of 'tester'@'%' to 'Dj.123456'...<<<${NC}"
$mysql -e "alter user 'tester'@'%' identified by 'Dj.123456'";
echo -e "${GREEN}>>>Check the pwd 'Dj.123456' of 'tester'@'%' if setted ok?<<<${NC}"
Tester_Pwd_Check=`mysql -utester -pDj.123456 -e "show databases" | grep Database | wc -l`
if [ $Tester_Pwd_Check -eq 1 ];then
echo -e "${GREEN}>>>The pwd of 'tester'@'%' setted right,and the pwd is 'Dj.123456',pls note...<<<${NC}"
else
echo -e "${RED}>>>Error:the pwd of 'tester'@'%' setted wrong,the pwd is not 'Dj.123456'<<<${NC}"
fi
else
echo -e "${GREEN}>>>Creating a new user 'tester'@'%' for mysql,set the pwd to 'Dj.123456'<<<${NC}"
$mysql -e "create user 'tester'@'%' identified by 'Dj.123456'";
$mysql -e "grant all privileges on *.* to tester@'%'";
$mysql -e "flush privileges";
$mysql -e "exit"
echo -e "${GREEN}>>>Restarting MySQL...<<<${NC}"
Mysql_Restart_2=`service mysqld restart`
Tester_Check_2=`mysql -utester -pDj.123456 -e "show databases" | grep Database | wc -l`
if [ ${Tester_Check_2} -eq 1 ];then
echo -e "${GREEN}>>>Mysql user 'tester' has been created,and the pwd is 'Dj.123456',pls note! <<<${NC}"
else
echo -e "${RED}>>>Error:the pwd of 'tester'@'%' setted wrong,and the pwd is not 'Dj.123456'<<<${NC}"
fi
fi
echo -e "${GREEN}>>>Checking the db ranzhi,using the user 'tester'@'%' to login...<<<${NC}"
Ranzhi_Db=`mysql -utester -pDj.123456 -e "show databases" | grep ranzhi | wc -l`
if [ $Ranzhi_Db -eq 1 ];then
echo -e "${YELLOW}>>>DB ranzhi is already exsited,will be dropped first,then recreated...<<<${NC}"
$mysql -e "drop database ranzhi";
Ranzhi_Db_2=`mysql -utester -pDj.123456 -e "show databases" | grep ranzhi | wc -l`
if [ ${Ranzhi_Db_2} -ne 1 ];then
echo -e "${GREEN}>>>DB ranzhi has been dropped...<<<${NC}"
else
echo -e "${RED}>>>DB ranzhi has not been dropped yet,you should drop it again...<<<${NC}"
fi
echo -e "${GREEN}>>>Creating the database ranzhi...<<<${NC}"
ranzhi_db_create=`mysql -utester -pDj.123456 -e "create database ranzhi DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"`
Ranzhi_Db_3=`mysql -utester -pDj.123456 -e "show databases" | grep ranzhi | wc -l`
if [ ${Ranzhi_Db_3} -eq 1 ];then
echo -e "${GREEN}>>>DB ranzhi has been created just now,you can import the ranzhi data next...<<<${NC}"
fi
echo -e "${GREEN}>>>Importing the ranzhi database from windows to linux...<<<${NC}"
dbUser='tester'
dbPassword='Dj.123456'
dbName='ranzhi'
mysql -u $dbUser -p$dbPassword -f $dbName -e "source /var/www/html/ranzhi.sql";
Ranzhi_Data=`mysql -utester -pDj.123456 -e "select count(*) from ranzhi.sys_user" | grep -v count`
if [ ${Ranzhi_Data} -ge 1 ];then
echo -e "${GREEN}>>>The data of db ranzhi moved from win to linux successfully...<<<${NC}"
else
echo -e "${RED}>>>The data of db ranzhi moved from win to linux failed...<<<${NC}"
fi
else
echo -e "${GREEN}>>>DB ranzhi does not exsit before,should be create a new database ranzhi now...<<<${NC}"
ranzhi_db_create=`mysql -utester -pDj.123456 -e "create database ranzhi DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;"`
Ranzhi_Db_4=`mysql -utester -pDj.123456 -e "show databases" | grep ranzhi | wc -l`
if [ ${Ranzhi_Db_4} -eq 1 ];then
echo -e "${GREEN}>>>Db ranzhi has been created just now,you can import the ranzhi data next...<<<${NC}"
else
echo -e "${RED}>>>Db ranzhi has not been created ok,can not import the data next...<<<${NC}"
fi
echo -e "${GREEN}>>>Importing the ranzhi database from windows to linux...<<<${NC}"
dbUser='tester'
dbPassword='Dj.123456'
dbName='ranzhi'
mysql -u $dbUser -p$dbPassword -f $dbName -e "source /var/www/html/ranzhi.sql";
Ranzhi_Data_2=`mysql -utester -pDj.123456 -e "select count(*) from ranzhi.sys_user" | grep -v count`
if [ ${Ranzhi_Data_2} -eq 1 ];then
echo -e "${GREEN}>>>DB ranzhi moved from Win to Linux successfully...<<<${NC}"
else
echo -e "${RED}>>>The data of ranzhi moved from Win to Linux failed...<<<${NC}"
fi
fi
echo -e "${GREEN}>>>Checking the installing of PHP5.6 in the system...<<<${NC}"
Php_Check=`php -v | grep 5.6 | wc -l`
if [ $Php_Check -eq 1 ];then
echo -e "${YELLOW}>>>Php5.6 has been installed,so no need to reinstall,pls note!<<<${NC}"
else
echo -e "${GREEN}>>>PHP5.6 has not been installed in this system,will be installed next...<<<${NC}"
echo -e "${GREEN}>>>Installing PHP5.6...<<<${NC}"
if [ ! -f "/var/www/html/php_mysql/epel-release-6-8.noarch.rpm" -o ! -f "/var/www/html/php_mysql/remi-release-6.rpm" ];then
echo -e "${RED}>>>Error:The 2 rpm packages:epel-release-6-8.noarch.rpm & remi-release-6.rpm must be in the directory '/var/www/html/php_mysql'<<<${NC}"
else
echo -e "${GREEN}>>>The 2 rpm packages:epel-release-6-8.noarch.rpm & remi-release-6.rpm are both in the directory '/var/www/html/php_mysql',just to install them...<<<${NC}"
echo -e "${GREEN}>>>Instaling the 2 rpm packages: epel-release-6-8.noarch.rpm & remi-release-6.rpm...<<<${NC}"
rpm_php=`rpm -Uvh /var/www/html/php_mysql/epel-release-6-8.noarch.rpm /var/www/html/php_mysql/remi-release-6.rpm`
echo -e "${GREEN}>>>Adding the deps for PHP5.6<<<${NC}"
echo -e "${YELLOW}>>>Will take a few minutes,please be patient...<<<${NC}"
deps=`yum install -y --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof php-pdo php-mysql php-gd`
Php_Check_2=`php -v | grep 5.6 | wc -l`
if [ ${Php_Check_2} -eq 1 ];then
echo -e "${GREEN}>>>Congratulations,PHP5.6 has been installed successfully...<<<${NC}"
else
echo -e "${RED}>>>Attentions: the PHP5.6 has not been installed successfully just now,pls reinstall it again...<<<${NC}"
fi
fi
fi
echo -e "${GREEN}>>>Checking the directory 'ranzhi' if existed in the directory '/var/www/html'<<<${NC}"
if [ -d "/var/www/html/ranzhi" ];then
echo -e "${YELLOW}>>>The directory 'ranzhi' existed in the directory '/var/www/html', should remove the old ranzhi directory first...<<<${NC}"
rm_ranzhi=`rm -rf ranzhi`
if [ ! -d "/var/www/html/ranzhi" ];then
echo -e "${GREEN}>>>The old directory '/var/www/html/ranzhi' has been removed just now,then to unzip the project package 'ranzhi.zip' to the project root path of apache<<<${NC}"
else
echo -e "${RED}>>>The old directory '/var/www/html/ranzhi' has not been removed just now,pls check!<<<${NC}"
fi
fi
echo -e "${GREEN}>>>Checking the file 'ranzhi.zip' if existed in the directory '/var/www/html'<<<${NC}"
if [ ! -f "/var/www/html/ranzhi.zip" ];then
echo -e "${RED}>>>The project file 'ranzhi.zip' not exsited,pls upload it to the directory '/var/www/html' first...<<<${NC}"
else
echo -e "${YELLOW}>>>The project file 'ranzhi.zip' exsited in the directory '/var/www/html',will unzip the file 'ranzhi.zip' to the directory '/var/www/html'...<<<${NC}"
Unzip_Ranzhi=`unzip /var/www/html/ranzhi.zip`
echo -e "${GREEN}>>>Checking the file 'ranzhi.zip' if unzipped to the directory '/var/www/html/ranzhi' ok?<<<${NC}"
if [ -d "/var/www/html/ranzhi" ];then
echo -e "${GREEN}>>>Good,all right,unzipped ok<<<${NC}"
else
echo -e "${RED}>>>Error:unzip failed,pls check the file 'ranzhi.zip' if zipped ok?<<<${NC}"
fi
fi
echo -e "${GREEN}>>>Checking the directory permissions of 'ranzhi' if or not '777'<<<${NC}"
Ranzhi_Permissions=`ls -l -d /var/www/html/ranzhi | grep rwxrwxrwx | wc -l`
if [ $Ranzhi_Permissions -ne 1 ];then
echo -e "${GREEN}>>The directory permissions of 'ranzhi' is not '777',will change it to '777' next...<<<${NC}"
echo -e "${GREEN}>>>chmodding the directory of '/var/www/html/ranzhi' with '777'...<<<${NC}"
Chmod_Ranzhi=`chmod -R 777 /var/www/html/ranzhi`
Ranzhi_Permissions_2=`ls -l -d /var/www/html/ranzhi | grep rwxrwxrwx | wc -l`
if [ ${Ranzhi_Permissions_2} -eq 1 ];then
echo -e "${GREEN}>>The directory permissions of 'ranzhi' has been changed to '777' just now!<<<${NC}"
else
echo -e "${RED}>>>Error:The directory permissions of 'ranzhi' has not been changed to '777',pls change it again!!!<<<${NC}"
fi
fi
echo -e "${GREEN}>>>Config the connection of database by modifing the file '/var/www/html/ranzhi/config/my.php'<<<${NC}"
if [ -f "/var/www/html/ranzhi/config/my.php" ];then
echo -e "${GREEN}>>>The file '/var/www/html/ranzhi/config/my.php' exist,will config the line 5,8,9 of the file 'ranzhi/config/my.php' now...<<<${NC}"
Vi_My_Php5=`sed -i "5s/'.*'/'localhost'/g" /var/www/html/ranzhi/config/my.php`
Vi_My_Php8=`sed -i "8s/'.*'/'tester'/g" /var/www/html/ranzhi/config/my.php`
Vi_My_Php9=`sed -i "9s/'.*'/'Dj.123456'/g" /var/www/html/ranzhi/config/my.php`
My_Config_8s=`head -8 /var/www/html/ranzhi/config/my.php | tail -1 | grep tester | wc -l`
if test $My_Config_8s = 1
then
echo -e "${GREEN}>>>The file '/ranzhi/config/my.php' has been modified ok!<<<${NC}"
else
echo -e "${RED}>>>The file '/ranzhi/config/my.php' has been modified failed!<<<${NC}"
fi
else
echo -e "${RED}>>>Error:The file '/var/www/html/ranzhi/config/my.php' not exsit,pls check...<<<${NC} "
fi
echo -e "${GREEN}>>>Checking the tmp directory of ranzhi if exsit?<<<${NC}"
if [ ! -d "/var/www/html/ranzhi/tmp" ];then
echo -e "${GREEN}>>>The ranzhi tmp directory does not exsit,should be removed before...<<<${NC}"
else
echo -e "${YELLOW}>>>The directory '/var/www/html/ranzhi/tmp' exist,will delete the ranzhi tmp directory...<<<${NC}"
rm_ranzhi_tmp=`rm -rf /var/www/html/ranzhi/tmp`
if [ ! -d "/var/www/html/ranzhi/tmp" ];then
echo -e "${GREEN}>>>The ranzhi tmp directory has been removed just now!<<<${NC}"
else
echo -e "${RED}>>>Error:The directory '/var/www/html/ranzhi/tmp' still exist,you should delete the ranzhi tmp directory again!!!<<<${NC}"
fi
fi
echo -e "${GREEN}>>>Checking the file '/etc/httpd/conf/httpd.conf' if backuped to 'httpd_bak.conf'<<<${NC}"
if [ -f /etc/httpd/conf/httpd_bak.conf ];then
echo -e "${YELLOW}>>>The config file 'httpd.conf' of apache have been backuped,no need to backup again...<<<${NC}"
else
echo -e "${GREEN}>>>Will backup the file 'httpd.conf'...<<<${NC}"
Bak_Httpd=`cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd_bak.conf`
if [ -f /etc/httpd/conf/httpd_bak.conf ];then
echo -e "${GREEN}>>>The config file 'httpd.conf' of apache have been backuped just now!<<<${NC}"
else
echo -e "${RED}>>>The file 'httpd.conf' has not been backuped just now,pls check...<<<${NC}"
fi
fi
echo -e "${GREEN}>>>Checking the line 338 of the file 'httpd.conf',if the string 'None' changed to 'All'?<<<${NC}"
Http_Conf_338=`head -338 /etc/httpd/conf/httpd.conf | tail -1 | grep None | wc -l`
if [ $Http_Conf_338 -eq 1 ];then
echo -e "${GREEN}>>>The string 'None' of the line 338 of the file 'httpd.conf' has not been modified yet,will alter the file 'httpd.conf',line 338: 'None' -'All'...<<<${NC}"
vi_http=`sed -i '338s/None/All/g' /etc/httpd/conf/httpd.conf`
Http_Conf_338_2=`cat -n /etc/httpd/conf/httpd.conf | head -338 | tail -1 | grep 'All$' | wc -l`
if [ ${Http_Conf_338_2} -eq 1 ];then
echo -e "${GREEN}>>>The string 'None' of the line 338 of the file 'httpd.conf' has been modified to 'All',pls note!<<<${NC}"
else
echo -e "${RED}>>>Error:the string 'None' of the line 338 of the file 'httpd.conf' has not been modified yet,pls rechang it again!!!<<<${NC}"
fi
else
echo -e "${YELLOW}>>>The 'None'->'All' in the line 338 has been modified before,so no need to modify again...<<<${NC}"
fi
echo -e "${GREEN}>>>Restarting Apache...<<<${NC}"
Httpd_Restart=`service httpd restart`
echo -e "${GREEN}>>>Project ranzhi from Win -Linux has been moved over,now you can visit the website to check if moved ok?!<<<${NC}"
:<<EOF
echo -e "${GREEN}>>>Important things are always should be said 3 times...<<<${NC}"
for((i=1;i<4;i++))
do
echo -e "${RED}>>>Attentions:pls disable the firewall with the commond 'setup'!If not,you cann't visit the ranzhi website outside.<<<${NC}"
done
echo -e "${GREEN}>>>Checking the status of firewall...<<<${NC}"
Firewall_Status=`service iptables status | grep "not running" | wc -l`
if test ${Firewall_Status} = 1
then
echo -e "${YELLOW}>>>The firewall in the system is disabled!!!You can visit the ranzhi website directly...<<<${NC}"
else
echo -e "${RED}>>>The firewall in the system is running!!!You can not visit the ranzhi website directly...pls disable it first!!!<<<${NC}"
fi
EOF
echo -e "${GREEN}>>>Checking the port 80 if setted ok to be visitted outside?<<<${NC}"
Check_Port_80_Open_Ok=`/sbin/iptables -L -n | grep 'dpt:80' | wc -l`
if [ $Check_Port_80_Open_Ok -ge 1 ];then
echo -e "${YELLOW}>>>The port 80 is setted ok before,no need to reset to open...<<<${NC}"
else
echo -e "${GREEN}>>>The port 80 is not setted open before,we will open the port 80 to be visitted outside...<<<${NC}"
Port_80_Open_Outside=`/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT`
# Open the port 3306 for mysql visitted outside by SQLYog
Port_3306_Open_Outside=`/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT`
Save_Iptables=`/etc/rc.d/init.d/iptables save`
Iptables_Restart=`/etc/init.d/iptables restart`
Check_Port_80_Open_Ok_2=`/sbin/iptables -L -n | grep 'dpt:80' | wc -l`
if [ ${Check_Port_80_Open_Ok_2} -ge 1 ];then
echo -e "${GREEN}>>>Congratulations,the port 80 is setted ok,you can visit the ranzhi website outside!!!<<<${NC}"
else
echo -e "${RED}>>>Error:the port 80 is setted open for visitted outside failed,you can not visit the ranzhi website outside,pls check!!!<<<${NC}"
fi
fi
echo -e "${GREEN}>>>Import things always said 3 times!!!<<<${NC}"
for i in {1..3}
do
echo -e "${SHAN_GREEN}>>>Now you can open the browser with typing the url:'http://LinuxIP/ranzhi/www' to visit the website of ranzhi,enjoy it!!!<<<${NC}"
done
End_Time=`date +%s`
Cost_Time=$(($End_Time-$Start_Time))
echo -e "${GREEN}>>>Start time is: ${Start_Time}, End time is:${End_Time}, the totle cost time is:${Cost_Time}seconds!<<<${NC}"
# call the function 'LingXing'
LingXing

以下为部分截图补充

必要的文件及存放路径.png 运行Shell脚本1.png 运行Shell脚本2.png 运行Shell脚本3.png 运行Shell脚本后,浏览器中打开 ranzhi.png

相关文章

  • 编写 Shell 脚本,实现环境移植(从 Windows 到 C

    说明: 项目以 ranzhi 为例(自己随便百度搜索 ranzhi 开源代码一大堆,可别告诉我你不会使用度娘喔) ...

  • shell脚本基础

    编写脚本 编程基础 shell脚本 创建shell脚本 变量 运算 测试 配置用户的环境

  • 指令随笔

    linux 修改shell脚本的编码 在window下编写的shell脚本编码为dos,在linux环境下不能直接...

  • shell脚本

    Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁.Shell 脚本(shell scri...

  • Powershell

    使用 Windows PowerShell 编写脚本 Powershell 是运行在windows机器上实现系统和...

  • mysql数据定时备份

    1.首先明白这里使用shell脚本编写 Shell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁...

  • Shell script + crontab实现Mysql定时备

    一、Shell 脚本 Shell 脚本(shell script),是一种为 shell 编写的脚本程序。 业界所...

  • shell脚本报错:-bash: xxx: /bin/sh^M:

    !/bin/bash echo "Hello World !" 在windows上编写的shell脚本然后再转到l...

  • 多命令处理

    编写shell脚本 执行脚本

  • shell脚本

    什么是shell脚本 Shell 脚本(shell script),是一种为 shell 编写的脚本程序。业界所说...

网友评论

      本文标题:编写 Shell 脚本,实现环境移植(从 Windows 到 C

      本文链接:https://www.haomeiwen.com/subject/hqakoftx.html