使其成为 shell 脚本的正确方法
Posted
技术标签:
【中文标题】使其成为 shell 脚本的正确方法【英文标题】:Proper way to make this a shell script 【发布时间】:2016-08-05 22:39:00 【问题描述】:大家好,任何人都可以指导我或重新编写我的脚本吗?好吧,我每次重新安装时都手动输入此代码。 我只想在 1 个脚本文件中完成这一切
yum update -y
yum install httpd -y
service httpd start
yum install mysql-server -y && service mysqld start && mysql_secure_installation
yum install php php-mysql -y && service httpd restart
rpm -ivh https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm && yum check-update && yum install phpMyAdmin -y
vi /etc/httpd/conf.d/phpMyAdmin.conf (Will edit some of line)
yum install git -y && yum install gcc make mysql mysql-devel mysql-server pcre-devel zlib-devel && yum -y install dos2unix gdb nano screen unzip wget zip
yum -y groupinstall Desktop && yum -y install tigervnc-server pixman pixman-devel libXfont
vncpasswd
vi /etc/sysconfig/vncservers
(Will write this on the bottom of vncservers)
VNCSERVERS="1:root"
VNCSERVERARGS[1]="-geometry 1100x768"
yum -y install xterm && yum -y install subversion && yum install gnome-utils -y && yum -y install nautilus-open-terminal
service vncserver start
chkconfig httpd on && chkconfig mysqld on && chkconfig vncserver on
reboot
===== 有没有人可以帮助我清理并将其仅放入 1 个文件中?
【问题讨论】:
把它放在一个文件里。使其可执行。运行它。 【参考方案1】:在您选择的某个目录中执行touch [script_name].sh
,然后在脚本中输入以下内容
#!/bin/bash
#if not sudo or root yum fails
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
yum update -y
yum install httpd -y
service httpd start
yum install mysql-server -y && service mysqld start && mysql_secure_installation
yum install php php-mysql -y && service httpd restart
rpm -ivh https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm && yum check-update && yum install phpMyAdmin -y
sed -i '24s/Deny from All/Allow from All/' /etc/httpd/conf.d/phpMyAdmin.conf
yum install git -y && yum install gcc make mysql mysql-devel mysql-server pcre-devel zlib-devel && yum -y install dos2unix gdb nano screen unzip wget zip
yum -y groupinstall Desktop && yum -y install tigervnc-server pixman pixman-devel libXfont
vncpasswd
echo VNCSERVERS="1:root" >> /etc/sysconfig/vncservers
echo VNCSERVERARGS[1]="-geometry 1100x768" >> /etc/sysconfig/vncservers
yum -y install xterm && yum -y install subversion && yum install gnome-utils -y && yum -y install nautilus-open-terminal
service vncserver start
chkconfig httpd on && chkconfig mysqld on && chkconfig vncserver on
echo rebooting computer
sleep 5
reboot
完成后退出文本编辑器并运行命令chmod +x /scriptpath/[script_name].sh
,然后运行cd
到包含脚本的目录并运行./[script_name].sh
。
【讨论】:
您好,感谢您的回复。在 /etc/httpd/conf.d/phpMyAdmin.conf 我要编辑第 24 行,即“全部拒绝”到“全部允许”我应该在脚本中输入什么代码? @Ranz 进行了编辑,使其转到第 24 行,并将内联 Deny from All 替换为 Allow from All以上是关于使其成为 shell 脚本的正确方法的主要内容,如果未能解决你的问题,请参考以下文章