KICKSTART无人值守安装系统shell3

#!/bin/bash

echo “This shell script requires 4 parameters”
echo “Has DHCP been installed? y or n? The default is n.”
echo “Has TFTP been installed? y or n? The default is n.”
echo “Has HTTP been installed? y or n? The default is n.”
echo “Has syslinux been installed? y or n? The default is n.”

if [ “$1” == “” ];then
dhcp_status=‘n’
else
dhcp_status=$1
fi

if [ “$2” == “” ];then
tftp_status=‘n’
else
tftp_status=$2
fi

if [ “$3” == “” ];then
http_status=‘n’
else
http_status=$3
fi

if [ “$4” == “” ];then
syslinux_status=‘n’
else
syslinux_status=$4
fi

function dhcp_install3(){
#安装DHCP(使用shell命令行参数和默认参数)
#(和select询问函数与自动检测函数不同时调用)
[ $dhcp_status == ‘n’ ] && yum -y install dhcp
}
dhcp_install3

function tftp_install3(){
#安装TFTP(使用shell命令行参数和默认参数)
#(和select询问函数与自动检测函数不同时调用)
[ $tftp_status == ‘n’ ] && yum -y install xinetd tftp-server
}
tftp_install3

function http_install3(){
#安装HTTP(使用shell命令行参数和默认参数)
#(和select询问函数与自动检测函数不同时调用)
[ $http_status == ‘n’ ] && yum -y install httpd
}
http_install3

function syslinux_install3(){
#安装syslinux(使用shell命令行参数和默认参数)
#(和select询问函数与自动检测函数不同时调用)
[ $syslinux_status == ‘n’ ] && yum -y install syslinux
}
syslinux_install3

function 也是拥有内建变量的,他的内建变量与shell script 很类似, 函数名称代表示 $0,而后续接的变量也是以 $1, $2… 来取代的。这里很容易搞错,因为function fname() { 程序段} 内的 $0, $1… 等等与 shell script 的 $0 是不同的。

netstat -ntulp |grep -w 21
if [ “$?” -eq “0” ]; then
echo “Other FTP is already installed”

Check if user is root

if [ $(id -u) != “0” ]; then
echo “Error: You must be root to run this script, please use root to install”
exit 1
fi

Check the OS

if [ “$(awk ‘{if ( $3 >= 7.0 ) print “CentOS 7.x”}’ /etc/redhat-release 2>/dev/null)” != “CentOS 7.x” ];then
err_echo “This script is used for RHEL/CentOS 7.x only.”
exit 1
fi
platform=uname -i
if [ $platform = “x86_64” ];then
echo " the platform is ok"
else
echo “this script is only for 64bit Operating System !”
exit 1
fi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值