第一次对我来说,我是个新手,我为我糟糕的英语和我的错误感到抱歉:)
我需要使用perl (或bash)编写一个安装脚本,但我仍然无法找到使它在不同的linux发行版中运行的方法。特别是,如果还没有安装httpd和mysql,那么这个脚本应该安装它们。我可以使用很多if -否则,但我想知道是否有任何自动系统,可以为我做,即使我找不到任何东西。示例:
伪码
//find httpd if is installed, if not it will try to install
try(service httpd status) ..
else try (service apache2 status)
if (not_installed) {
try yum install httpd
else try apt-get install apache2
else try pacman ....
}我在想一些类似于自动工具的东西。它存在吗?
谢谢大家:)
发布于 2014-02-27 13:53:24
‘$^O变量将报告您所使用的操作系统,请参阅部分了解此部分的工作方式
perl还有一个Config模块,它包含perl在编译时使用类似于autotools的方法得到的所有信息。
Config手册页中的这个示例程序显示了可用的信息。
use Config;
if ($Config{usethreads}) {
print "has thread support\n"
}
use Config qw(myconfig config_sh config_vars config_re);
print myconfig();
print config_sh();
config_vars(qw(osname archname));顺便说一句,木偶很擅长在不同的平台上安装软件包,并在不同的配置路径上进行配置。虽然它使用的是ruby,所以可能与工具链的其余部分不匹配。
发布于 2014-02-27 13:52:44
您可以使用chkconfig -list查找已安装的服务。
像这样的事情是可以做到的:
#!/bin/bash
chkmysql=`chkconfig --list | grep mysql | wc -l`
chkhttp=`chkconfig --list | grep http | wc -l`
if [[ chkmysql > 0 ]]
then
echo "mysql is installed"
else
echo "mysql is not installed"
#write code to install mysql
fi
if [[ chkhttp > 0 ]]
then
echo "http is installed"
else
echo "http is not installed"
#write code to install httpd service
fi发布于 2014-02-27 14:02:39
由于您不运行一次性安装,我假设您处于某种sys管理角色。你看过linux启动吗?“启动”允许您以完全您想要的方式获得系统,然后将其映像到远程安装中。这样,如果一个系统出现故障,它就可以以最小的外部依赖性快速恢复。建立一个系统的自愈方法的问题是,它可以引起更多的问题,然后它解决了当它不能正确工作。$0.02
https://stackoverflow.com/questions/22070323
复制相似问题