bash - Bash Script If else to change PHP-FPM version not working [Virtualmin]
问题描述
#!/bin/bash
# allfpm means reload all three fpm service (5.6/7.0/7.2) and nginx
# All below three dir path will have one file (for e.g example.com.conf ) at one time. Either php56 include dir will have this file or 7.0 or 7.2.
#7.0
php_v70=/etc/opt/rh/rh-php70/php-fpm.d/
#5.6
php_v56=/opt/remi/php56/root/etc/php-fpm.d/
#7.2
php_v72=/etc/php-fpm.d/
read -p 'Enter Website Name: (without www) :- ' site_name
#echo "============================================="
#echo "========== Enter Website's Name ============="
#echo "============================================="
#read -p 'Enter Website Name: (without www) :- ' site_name
#echo "============================================="
#echo "= Choose PHP Version, e.g 5.6 or 7.0 or 7.2 ="
#echo "============================================="
#read -p 'Choose PHP Version (e.g 56 or 70 or 72) :- ' php_ver
site_username=`virtualmin list-domains | grep $site_name | awk '{print $2}'`
rm -vf /home/"$site_username"/public_html/php_ver.php
sleep 2
cp /root/scripts/php_ver.php /home/$site_username/public_html/
chown $site_username: /home/$site_username/public_html/php_ver.php
current_php_ver=`curl -s $site_name/php_ver.php | cut -c1-3 | sed -r 's/\./\ /g' | sed 's/ //g'`
echo "Currently $site_name is running on PHP-FPM $current_php_ver"
read -p 'Choose PHP Version (e.g 56 or 70 or 72) :- ' php_ver
# Condition # 1
#p70=7.0
#p56=5.6
#p72=7.2
if [ $current_php_ver -eq 56 ] || [ $php_ver -eq 70 ]
then
mv $php_v56$site_name.conf $php_v70
# Reload PHP 5.6, PHP 7.0 and Nginx here
allfpm
exit
else
# Condition # 2
if [ $current_php_ver -eq 56 ] || [ $php_ver -eq 72 ]
then
mv $php_v56$site_name.conf $php_v72
# Reload PHP 5.6, PHP 7.2 and Nginx here
allfpm
exit
else
# Condition # 3
if [ $current_php_ver -eq 70 ] || [ $php_ver -eq 72 ]
then
mv $php_v70$site_name.conf $php_v72
# Reload PHP 7.0, PHP 7.2 and Nginx here
allfpm
exit
else
# Condition # 4
if [ $current_php_ver -eq 70 ] || [ $php_ver -eq 56 ]
then
mv $php_v70$site_name.conf $php_v56
# Reload PHP 7.0, PHP 5.6 and Nginx here
allfpm
exit
else
# Condition # 5
if [ $current_php_ver -eq 72 ] || [ $php_ver -eq 56 ]
then
mv $php_v72$site_name.conf $php_v56
# Reload PHP 7.2, PHP 5.6 and Nginx here
allfpm
exit
else
# Condition # 6
if [ $current_php_ver -eq 72 ] || [ $php_ver -eq 70 ]
then
mv $php_v72$site_name.conf $php_v70
# Reload PHP 7.2, PHP 7.0 and Nginx here
allfpm
exit
fi
fi
fi
fi
fi
fi
概述:-此脚本将更改找出当前运行的 php-fpm 版本,然后它会询问选择,例如 5.6、7.0、7.2,然后将一个 .conf 移动到相应的 php-fpm 包含目录,在该 fpm 之后services + nginx 将被重新加载。
问题:-当当前版本是 7.2 并且选择是 7.0 时,它仍然调用 #1 条件,我已经用 echo 消息对其进行了测试,以确保它不能像我想要的那样工作。
请帮忙。
解决方案
推荐阅读
- laravel - 如何在 Laravel 中使用 Laravel Excel 设置导出 csv 的编码
- html - 如何使所有div的高度相等?
- html - 为什么推荐主图使用 16:9 的比例?
- javascript - 如何使用胖箭头 es6 语法重写此嵌套调用以设置?
- racket - 向球拍中的类添加类型注释
- python - BeautifulSoup 网页抓取,用于点击按钮后获取信息的网页
- flutter - 如何将文本文件加载到 Flutter 中的字符串变量中
- c# - 修改 ListView 项目时自动调整 ListView 高度
- python - Tkinter 窗口和 pygame 窗口同时打开
- reactjs - 如何更改 Material-UI Button 的 tabIndex?