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

猜你喜欢

转载自blog.csdn.net/qq_41906344/article/details/82948059
今日推荐