四年前我面临即将失业(毕业)的人生重大转折点也是我与小C相识的一年,初入C站只想着记录一下学习笔记也没什么目标,久而久之养成了习惯,大学生活逐渐接近尾声,那时候心里想着每个月工资能有一份四五千的工作就很知足了,后来遇到了云计算浪潮,很幸运我的专业正好对口,就这我怀着对社会的憧憬一股脑扎进了IT行业开启了IT之旅~
在北漂的四年很多过客来来往往,唯有小C始终不离不弃的陪伴着我,各方面使我获益良多:
我与小C的关系亦师亦友:
人生中第一个还比较写的不错的bash代码:
#!/bin/bash
APP_NAME="${0##*[\\/]}"
APP_VERSION="1.0"#颜色定义
cRed=1
cGreen=2
cYellow=3
cBlue=4
cFuchsia=5
cCyan=6
cWhite=7
colorTable=($cRed $cGreen $cYellow $cBlue $cFuchsia $cCyan $cWhite)#位置和大小
iLeft=3
iTop=2
((iTrayLeft = iLeft + 2))
((iTrayTop = iTop + 1))
((iTrayWidth = 10))
((iTrayHeight = 15))#颜色设置
cBorder=$cGreen
cScore=$cFuchsia
cScoreValue=$cCyan#控制信号
#改游戏使用两个进程,一个用于接收输入,一个用于游戏流程和显示界面;
#当前者接收到上下左右等按键时,通过向后者发送signal的方式通知后者。
sigRotate=25
sigLeft=26
sigRight=27
sigDown=28
sigAllDown=29
sigExit=30#七中不同的方块的定义
#通过旋转,每种方块的显示的样式可能有几种
box0=(0 0 0 1 1 0 1 1)
box1=(0 2 1 2 2 2 3 2 1 0 1 1 1 2 1 3)
box2=(0 0 0 1 1 1 1 2 0 1 1 0 1 1 2 0)
box3=(0 1 0 2 1 0 1 1 0 0 1 0 1 1 2 1)
box4=(0 1 0 2 1 1 2 1 1 0 1 1 1 2 2 2 0 1 1 1 2 0 2 1 0 0 1 0 1 1 1 2)
box5=(0 1 1 1 2 1 2 2 1 0 1 1 1 2 2 0 0 0 0 1 1 1 2 1 0 2 1 0 1 1 1 2)
box6=(0 1 1 1 1 2 2 1 1 0 1 1 1 2 2 1 0 1 1 0 1 1 2 1 0 1 1 0 1 1 1 2)
#所有其中方块的定义都放到box变量中
box=(${box0[@]} ${box1[@]} ${box2[@]} ${box3[@]} ${box4[@]} ${box5[@]} ${box6[@]})
#各种方块旋转后可能的样式数目
countBox=(1 2 2 2 4 4 4)
#各种方块再box数组中的偏移
offsetBox=(0 1 3 5 7 11 15)#每提高一个速度级需要积累的分数
iScoreEachLevel=50 #be greater than 7#运行时数据
sig=0 #接收到的signal
iScore=0 #总分
iLevel=0 #速度级
boxNew=() #新下落的方块的位置定义
cBoxNew=0 #新下落的方块的颜色
iBoxNewType=0 #新下落的方块的种类
iBoxNewRotate=0 #新下落的方块的旋转角度
boxCur=() #当前方块的位置定义
cBoxCur=0 #当前方块的颜色
iBoxCurType=0 #当前方块的种类
iBoxCurRotate=0 #当前方块的旋转角度
boxCurX=-1 #当前方块的x坐标位置
boxCurY=-1 #当前方块的y坐标位置
iMap=() #背景方块图表#初始化所有背景方块为-1, 表示没有方块
for ((i = 0; i < iTrayHeight * iTrayWidth; i++)); do iMap[$i]=-1; done#接收输入的进程的主函数
function RunAsKeyReceiver()
{local pidDisplayer key aKey sig cESC sTTYpidDisplayer=$1aKey=(0 0 0)cESC=`echo -ne "\033"`cSpace=`echo -ne "\040"`#保存终端属性。在read -s读取终端键时,终端的属性会被暂时改变。#如果在read -s时程序被不幸杀掉,可能会导致终端混乱,#需要在程序退出时恢复终端属性。sTTY=`stty -g`#捕捉退出信号trap "MyExit;" INT TERMtrap "MyExitNoSub;" $sigExit#隐藏光标echo -ne "\033[?25l"while :do#读取输入。注-s不回显,-n读到一个字符立即返回read -s -n 1 keyaKey[0]=${aKey[1]}aKey[1]=${aKey[2]}aKey[2]=$keysig=0#判断输入了何种键if [[ $key == $cESC && ${aKey[1]} == $cESC ]]then#ESC键MyExitelif [[ ${aKey[0]} == $cESC && ${aKey[1]} == "[" ]]thenif [[ $key == "A" ]]; then sig=$sigRotate #<向上键>elif [[ $key == "B" ]]; then sig=$sigDown #<向下键>elif [[ $key == "D" ]]; then sig=$sigLeft #<向左键>elif [[ $key == "C" ]]; then sig=$sigRight #<向右键>fielif [[ $key == "W" || $key == "w" ]]; then sig=$sigRotate #W, welif [[ $key == "S" || $key == "s" ]]; then sig=$sigDown #S, selif [[ $key == "A" || $key == "a" ]]; then sig=$sigLeft #A, aelif [[ $key == "D" || $key == "d" ]]; then sig=$sigRight #D, delif [[ "[$key]" == "[]" ]]; then sig=$sigAllDown #空格键elif [[ $key == "Q" || $key == "q" ]] #Q, qthenMyExitfiif [[ $sig != 0 ]]then#向另一进程发送消息kill -$sig $pidDisplayerfidone
}#退出前的恢复
function MyExitNoSub()
{local y#恢复终端属性stty $sTTY((y = iTop + iTrayHeight + 4))#显示光标echo -e "\033[?25h\033[${y};0H"exit
}function MyExit()
{#通知显示进程需要退出kill -$sigExit $pidDisplayerMyExitNoSub
}#处理显示和游戏流程的主函数
function RunAsDisplayer()
{local sigThisInitDraw#挂载各种信号的处理函数trap "sig=$sigRotate;" $sigRotatetrap "sig=$sigLeft;" $sigLefttrap "sig=$sigRight;" $sigRighttrap "sig=$sigDown;" $sigDowntrap "sig=$sigAllDown;" $sigAllDowntrap "ShowExit;" $sigExitwhile :do#根据当前的速度级iLevel不同,设定相应的循环的次数for ((i = 0; i < 21 - iLevel; i++))dosleep 0.02sigThis=$sigsig=0#根据sig变量判断是否接受到相应的信号if ((sigThis == sigRotate)); then BoxRotate; #旋转elif ((sigThis == sigLeft)); then BoxLeft; #左移一列elif ((sigThis == sigRight)); then BoxRight; #右移一列elif ((sigThis == sigDown)); then BoxDown; #下落一行elif ((sigThis == sigAllDown)); then BoxAllDown; #下落到底fidone#kill -$sigDown $$BoxDown #下落一行done
}#BoxMove(y, x), 测试是否可以把移动中的方块移到(x, y)的位置, 返回0则可以, 1不可以
function BoxMove()
{local j i x y xTest yTestyTest=$1xTest=$2for ((j = 0; j < 8; j += 2))do((i = j + 1))((y = ${boxCur[$j]} + yTest))((x = ${boxCur[$i]} + xTest))if (( y < 0 || y >= iTrayHeight || x < 0 || x >= iTrayWidth))then#撞到墙壁了return 1fiif ((${iMap[y * iTrayWidth + x]} != -1 ))then#撞到其他已经存在的方块了return 1fidonereturn 0;
}#将当前移动中的方块放到背景方块中去,
#并计算新的分数和速度级。(即一次方块落到底部)
function Box2Map()
{local j i x y xp yp line#将当前移动中的方块放到背景方块中去for ((j = 0; j < 8; j += 2))do((i = j + 1))((y = ${boxCur[$j]} + boxCurY))((x = ${boxCur[$i]} + boxCurX))((i = y * iTrayWidth + x))iMap[$i]=$cBoxCurdone#消去可被消去的行line=0for ((j = 0; j < iTrayWidth * iTrayHeight; j += iTrayWidth))dofor ((i = j + iTrayWidth - 1; i >= j; i--))doif ((${iMap[$i]} == -1)); then break; fidoneif ((i >= j)); then continue; fi((line++))for ((i = j - 1; i >= 0; i--))do((x = i + iTrayWidth))iMap[$x]=${iMap[$i]}donefor ((i = 0; i < iTrayWidth; i++))doiMap[$i]=-1donedoneif ((line == 0)); then return; fi#根据消去的行数line计算分数和速度级((x = iLeft + iTrayWidth * 2 + 7))((y = iTop + 11))((iScore += line * 2 - 1))#显示新的分数echo -ne "\033[1m\033[3${cScoreValue}m\033[${y};${x}H${iScore} "if ((iScore % iScoreEachLevel < line * 2 - 1))thenif ((iLevel < 20))then((iLevel++))((y = iTop + 14))#显示新的速度级echo -ne "\033[3${cScoreValue}m\033[${y};${x}H${iLevel} "fifiecho -ne "\033[0m"#重新显示背景方块for ((y = 0; y < iTrayHeight; y++))do((yp = y + iTrayTop + 1))((xp = iTrayLeft + 1))((i = y * iTrayWidth))echo -ne "\033[${yp};${xp}H"for ((x = 0; x < iTrayWidth; x++))do((j = i + x))if ((${iMap[$j]} == -1))thenecho -ne " "elseecho -ne "\033[1m\033[7m\033[3${iMap[$j]}m\033[4${iMap[$j]}m[]\033[0m"fidonedone
}#下落一行
function BoxDown()
{local y s((y = boxCurY + 1)) #新的y坐标if BoxMove $y $boxCurX #测试是否可以下落一行thens="`DrawCurBox 0`" #将旧的方块抹去((boxCurY = y))s="$s`DrawCurBox 1`" #显示新的下落后方块echo -ne $selse#走到这儿, 如果不能下落了Box2Map #将当前移动中的方块贴到背景方块中RandomBox #产生新的方块fi
}#左移一列
function BoxLeft()
{local x s((x = boxCurX - 1))if BoxMove $boxCurY $xthens=`DrawCurBox 0`((boxCurX = x))s=$s`DrawCurBox 1`echo -ne $sfi
}#右移一列
function BoxRight()
{local x s((x = boxCurX + 1))if BoxMove $boxCurY $xthens=`DrawCurBox 0`((boxCurX = x))s=$s`DrawCurBox 1`echo -ne $sfi
}#下落到底
function BoxAllDown()
{local k j i x y iDown siDown=$iTrayHeight#计算一共需要下落多少行for ((j = 0; j < 8; j += 2))do((i = j + 1))((y = ${boxCur[$j]} + boxCurY))((x = ${boxCur[$i]} + boxCurX))for ((k = y + 1; k < iTrayHeight; k++))do((i = k * iTrayWidth + x))if (( ${iMap[$i]} != -1)); then break; fidone((k -= y + 1))if (( $iDown > $k )); then iDown=$k; fidones=`DrawCurBox 0` #将旧的方块抹去((boxCurY += iDown))s=$s`DrawCurBox 1` #显示新的下落后的方块echo -ne $sBox2Map #将当前移动中的方块贴到背景方块中RandomBox #产生新的方块
}#旋转方块
function BoxRotate()
{local iCount iTestRotate boxTest j i siCount=${countBox[$iBoxCurType]} #当前的方块经旋转可以产生的样式的数目#计算旋转后的新的样式((iTestRotate = iBoxCurRotate + 1))if ((iTestRotate >= iCount))then((iTestRotate = 0))fi#更新到新的样式, 保存老的样式(但不显示)for ((j = 0, i = (${offsetBox[$iBoxCurType]} + $iTestRotate) * 8; j < 8; j++, i++))doboxTest[$j]=${boxCur[$j]}boxCur[$j]=${box[$i]}doneif BoxMove $boxCurY $boxCurX #测试旋转后是否有空间放的下then#抹去旧的方块for ((j = 0; j < 8; j++))doboxCur[$j]=${boxTest[$j]}dones=`DrawCurBox 0`#画上新的方块for ((j = 0, i = (${offsetBox[$iBoxCurType]} + $iTestRotate) * 8; j < 8; j++, i++))doboxCur[$j]=${box[$i]}dones=$s`DrawCurBox 1`echo -ne $siBoxCurRotate=$iTestRotateelse#不能旋转,还是继续使用老的样式for ((j = 0; j < 8; j++))doboxCur[$j]=${boxTest[$j]}donefi
}#DrawCurBox(bDraw), 绘制当前移动中的方块, bDraw为1, 画上, bDraw为0, 抹去方块。
function DrawCurBox()
{local i j t bDraw sBox sbDraw=$1s=""if (( bDraw == 0 ))thensBox="\040\040"elsesBox="[]"s=$s"\033[1m\033[7m\033[3${cBoxCur}m\033[4${cBoxCur}m"fifor ((j = 0; j < 8; j += 2))do((i = iTrayTop + 1 + ${boxCur[$j]} + boxCurY))((t = iTrayLeft + 1 + 2 * (boxCurX + ${boxCur[$j + 1]})))#\033[y;xH, 光标到(x, y)处s=$s"\033[${i};${t}H${sBox}"dones=$s"\033[0m"echo -n $s
}#更新新的方块
function RandomBox()
{local i j t#更新当前移动的方块iBoxCurType=${iBoxNewType}iBoxCurRotate=${iBoxNewRotate}cBoxCur=${cBoxNew}for ((j = 0; j < ${#boxNew[@]}; j++))doboxCur[$j]=${boxNew[$j]}done#显示当前移动的方块if (( ${#boxCur[@]} == 8 ))then#计算当前方块该从顶端哪一行"冒"出来for ((j = 0, t = 4; j < 8; j += 2))doif ((${boxCur[$j]} < t)); then t=${boxCur[$j]}; fidone((boxCurY = -t))for ((j = 1, i = -4, t = 20; j < 8; j += 2))doif ((${boxCur[$j]} > i)); then i=${boxCur[$j]}; fiif ((${boxCur[$j]} < t)); then t=${boxCur[$j]}; fidone((boxCurX = (iTrayWidth - 1 - i - t) / 2))#显示当前移动的方块echo -ne `DrawCurBox 1`#如果方块一出来就没处放,Game over!if ! BoxMove $boxCurY $boxCurXthenkill -$sigExit ${PPID}ShowExitfifi#清除右边预显示的方块for ((j = 0; j < 4; j++))do((i = iTop + 1 + j))((t = iLeft + 2 * iTrayWidth + 7))echo -ne "\033[${i};${t}H "done#随机产生新的方块((iBoxNewType = RANDOM % ${#offsetBox[@]}))((iBoxNewRotate = RANDOM % ${countBox[$iBoxNewType]}))for ((j = 0, i = (${offsetBox[$iBoxNewType]} + $iBoxNewRotate) * 8; j < 8; j++, i++))doboxNew[$j]=${box[$i]};done((cBoxNew = ${colorTable[RANDOM % ${#colorTable[@]}]}))#显示右边预显示的方块echo -ne "\033[1m\033[7m\033[3${cBoxNew}m\033[4${cBoxNew}m"for ((j = 0; j < 8; j += 2))do((i = iTop + 1 + ${boxNew[$j]}))((t = iLeft + 2 * iTrayWidth + 7 + 2 * ${boxNew[$j + 1]}))echo -ne "\033[${i};${t}H[]"doneecho -ne "\033[0m"
}#初始绘制
function InitDraw()
{clearRandomBox #随机产生方块,这时右边预显示窗口中有方快了RandomBox #再随机产生方块,右边预显示窗口中的方块被更新,原先的方块将开始下落local i t1 t2 t3#显示边框echo -ne "\033[1m"echo -ne "\033[3${cBorder}m\033[4${cBorder}m"((t2 = iLeft + 1))((t3 = iLeft + iTrayWidth * 2 + 3))for ((i = 0; i < iTrayHeight; i++))do((t1 = i + iTop + 2))echo -ne "\033[${t1};${t2}H||"echo -ne "\033[${t1};${t3}H||"done((t2 = iTop + iTrayHeight + 2))for ((i = 0; i < iTrayWidth + 2; i++))do((t1 = i * 2 + iLeft + 1))echo -ne "\033[${iTrayTop};${t1}H=="echo -ne "\033[${t2};${t1}H=="doneecho -ne "\033[0m"#显示"Score"和"Level"字样echo -ne "\033[1m"((t1 = iLeft + iTrayWidth * 2 + 7))((t2 = iTop + 10))echo -ne "\033[3${cScore}m\033[${t2};${t1}HScore"((t2 = iTop + 11))echo -ne "\033[3${cScoreValue}m\033[${t2};${t1}H${iScore}"((t2 = iTop + 13))echo -ne "\033[3${cScore}m\033[${t2};${t1}HLevel"((t2 = iTop + 14))echo -ne "\033[3${cScoreValue}m\033[${t2};${t1}H${iLevel}"echo -ne "\033[0m"
}#退出时显示GameOVer!
function ShowExit()
{local y((y = iTrayHeight + iTrayTop + 3))echo -e "\033[${y};0HGameOver!\033[0m"exit
}#显示用法.
function Usage
{cat << EOF
Usage: $APP_NAME
Start tetris game.-h, --help display this help and exit--version output version information and exit
EOF
}#游戏主程序在这儿开始.
if [[ "$1" == "-h" || "$1" == "--help" ]]; thenUsage
elif [[ "$1" == "--version" ]]; thenecho "$APP_NAME $APP_VERSION"
elif [[ "$1" == "--show" ]]; then#当发现具有参数--show时,运行显示函数RunAsDisplayer
elsebash $0 --show& #以参数--show将本程序再运行一遍RunAsKeyReceiver $! #以上一行产生的进程的进程号作为参数
fi
#!/bin/bash
#===========================================================================
# FileName: RHCE-AK.auto
#
# Author : WangXinKun
#
# Created : 11:07,03/08/2019
#===========================================================================
#说明:用前请打通墙壁(server0生成公钥及传输给desktop0私钥)请使用以下指令:
#ssh-keygen(一路回车即可);ssh-copy-id root@172.25.0.xx(写desktop ip)
#firewall-cmd --set-default-zone=trusted(两边都要打开,否则无法配置desktop0)
cecho () {
echo -e " | \033[1;32mC\033[0m \033[1;33mS\033[0m \033[1;35mD\033[0m \033[1;36mN\033[0m \E[1;35m阿\033[0m \033[1;34m坤\033[0m |"
}echo ' .-"""-. '
echo " / .===. \ "
echo " \/ 6 6 \/ "
echo " ( \___/ ) "
echo " _________ooo__\_____/_____________ "
echo " / \ "cecho
echo " \_______________________ooo________/ "
echo " | | | "
echo " |_ | _| "
echo " | | | "
echo " |__|__| "
echo " /-'Y'-\ "
echo " (__/ \__) "echo "=====================Oo欢迎使用阿坤脚本,祝您使用愉快oO==========================="
echo -e "* \033[36mOoRHCE-AK自动答题开始oO\033[0m *"
a=!
mainconfig () {sed -i 's/#relayhost = [gateway.my.domain]/relayhost = [smtp0.example.com]/g' /etc/postfix/main.cfsed -i 's/#myorigin = $myhostname/myorigin = desktop0.example.com/g' /etc/postfix/main.cfsed -i 's/inet_interfaces = all/inet_interfaces = loopback-only/g' /etc/postfix/main.cfsed -i 's/#mynetworks = 168.100.189.0\/28, 127.0.0.0\/8/mynetworks = 127.0.0.0\/8 [::1]\/128/g' /etc/postfix/main.cfsed -i 's/mydestination = $myhostname, localhost.$mydomain, localhost/mydestination = /g' /etc/postfix/main.cfecho "local_transport = error:local delivery disabled" >> /etc/postfix/main.cf
}
#配置SELinux:
#desktop0
ssh root@172.25.0.10 </dev/null
setenforce 1 &&
echo "
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
" > /etc/selinux/config
grep "SELINUX=enforcing" /etc/selinux/config &>/dev/null
if [ $? -eq 0 ]thenecho -e "* \E[35m01.\033[0m配置SELinux服务-----------------------\033[33m[ OK$a]\033[0m *"elseecho -e "配置SELinux服务------------------\033[31m[Failed$a]\033[0m"
fi
EOF
#server0
setenforce 1 &&
echo "
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
" > /etc/selinux/config
grep "SELINUX=enforcing" /etc/selinux/config &>/dev/null
if [ $? -eq 0 ]thenecho -e "* \E[35m01.\033[0m配置SELinux服务-----------------------\033[33m[ OK$a]\033[0m *"elseecho -e "配置SELinux服务------------------\033[31m[Failed$a]\033[0m"
fi
#配置SSH访问:
#desktop0
ssh root@172.25.0.10 </dev/null
echo ok
if [ $? -eq 0 ]thenfirewall-cmd --permanent --zone=block --add-source=172.34.0.0/24elsebreak
fi
grep "172.34.0.0/24" /etc/firewalld/zones/block.xml &>/dev/null
if [ $? -eq 0 ]thenecho -e "配置SSH访问------------------\033[33m[OK$a]\033[0m"elseecho -e "配置SSH访问------------------\033[31m[Failed$a]\033[0m"
fi
EOF
#server0
if [ $? -eq 0 ]thenfirewall-cmd --permanent --zone=block --add-source=172.34.0.0/24 &>/dev/nullelsebreak
fi
grep "172.34.0.0/24" /etc/firewalld/zones/block.xml &>/dev/null
if [ $? -eq 0 ]thenecho -e "* \E[35m02.\033[0m配置SSH访问---------------------------\033[33m[ OK$a]\033[0m *"elseecho -e "配置SSH访问------------------\033[31m[Failed$a]\033[0m"
fi
firewall-cmd --reload &>/dev/null &&
#自定义用户环境:
#server0
if [ $? -eq 0 ]thenecho "alias qstat='/bin/ps -Ao pid,tt,user,fname,rsz'" >> /etc/bashrcelsebreak
fi
grep "alias qstat='/bin/ps -Ao pid,tt,user,fname,rsz'" /etc/bashrc &>/dev/null
if [ $? -eq 0 ]thenecho -e "* \E[35m03.\033[0m配置别名定义--------------------------\033[33m[ OK$a]\033[0m *"else echo -e "qstat别名定义------------------\033[31m[Failed$a]\033[0m"
fi
source /etc/bashrc
qstat &>/dev/null
#desktop0
ssh root@172.25.0.10 </dev/null
echo ok
if [ $? -eq 0 ]thenecho "alias qstat='/bin/ps -Ao pid,tt,user,fname,rsz'" >> /etc/bashrcelsebreak
fi
grep "alias qstat='/bin/ps -Ao pid,tt,user,fname,rsz'" /etc/bashrc &>/dev/null
if [ $? -eq 0 ]thenecho -e "qstat别名定义------------------\033[33m[OK$a]\033[0m"else echo -e "qstat别名定义------------------\033[31m[Failed$a]\033[0m"
fi
source /etc/bashrc
qstat &>/dev/null
EOF
#配置防火墙端口转发:
#desktop0
ssh root@172.25.0.10 </dev/null
echo ok
if [ $? -eq 0 ]thenfirewall-cmd --permanent --zone=trusted --add-forward-port=port=5423:proto=tcp:toport=80 &>/dev/nullelsebreak
fi
egrep "forward-port to-port=\"80\" protocol=\"tcp\" port=\"5423\"" /etc/firewalld/zones/trusted.xml &>/dev/null
if [ $? -eq 0 ]thenecho -e "Firewall端口转发------------------\033[33m[OK$a]\033[0m"elseecho -e "Firewall端口转发------------------\033[31m[Failed$a]\033[0m"
fi
firewall-cmd --reload
EOF
#server0
if [ $? -eq 0 ]thenfirewall-cmd --permanent --zone=trusted --add-forward-port=port=5423:proto=tcp:toport=80 &>/dev/nullelsebreak
fi
egrep "forward-port to-port=\"80\" protocol=\"tcp\" port=\"5423\"" /etc/firewalld/zones/trusted.xml &>/dev/null
if [ $? -eq 0 ]thenecho -e "* \E[35m04.\033[0m配置端口转发--------------------------\033[33m[ OK$a]\033[0m *"elseecho -e "Firewall端口转发------------------\033[31m[Failed$a]\033[0m"
fi
firewall-cmd --reload &>/dev/null &&
#配置链路聚合:
#desktop0
ssh root@172.25.0.10 </dev/null
echo ok
if [ $? -eq 0 ]thennmcli connection add type team ifname team0 con-name team0 autoconnect yes config '{"runner": {"name": "activebackup"}}' &>/dev/nullnmcli connection add type team-slave ifname eth1 con-name team0-1 master team0 &>/dev/nullnmcli connection add type team-slave ifname eth2 con-name team0-2 master team0 &>/dev/nullnmcli connection modify team0-1 connection.autoconnect yesnmcli connection modify team0-2 connection.autoconnect yesnmcli connection modify team0 ipv4.method manual ipv4.addresses '172.16.3.25/24' connection.autoconnect yeselsebreak
fi
nmcli connection up team0 &>/dev/null
if [ $? -eq 0 ]thenecho -e "Team0链路聚合------------------\033[33m[OK$a]\033[0m"elseecho -e "Team0链路聚合------------------\033[31m[Failed$a]\033[0m"
fi
teamdctl team0 state &>/dev/null
EOF
#server0
if [ $? -eq 0 ]thennmcli connection add type team ifname team0 con-name team0 autoconnect yes config '{"runner": {"name": "activebackup"}}' &>/dev/nullnmcli connection add type team-slave ifname eth1 con-name team0-1 master team0 &>/dev/nullnmcli connection add type team-slave ifname eth2 con-name team0-2 master team0 &>/dev/nullnmcli connection modify team0-1 connection.autoconnect yesnmcli connection modify team0-2 connection.autoconnect yesnmcli connection modify team0 ipv4.method manual ipv4.addresses '172.16.3.20/24' connection.autoconnect yeselsebreak
fi
nmcli connection up team0 &>/dev/null
if [ $? -eq 0 ]thenecho -e "* \E[35m05.\033[0m配置链路聚合--------------------------\033[33m[ OK$a]\033[0m *"elseecho -e "Team0链路聚合------------------\033[31m[Failed$a]\033[0m"
fi
teamdctl team0 state &>/dev/null &&
#配置IPv6地址:
#desktop0
ssh root@172.25.0.10 </dev/null
echo ok
if [ $? -eq 0 ]thennmcli connection modify 'System eth0' ipv6.method manual ipv6.addresses '2003:ac18::306/64' connection.autoconnect yes elsebreak
fi
nmcli connection up 'System eth0' &>/dev/null
if [ $? -eq 0 ]thenecho -e "配置IPv6地址------------------\033[33m[OK$a]\033[0m"elseecho -e "配置IPv6地址------------------\033[31m[Failed$a]\033[0m"
fi
hostnamectl set-hostname desktop0.example.com
EOF
#server0
if [ $? -eq 0 ]thennmcli connection modify 'System eth0' ipv6.method manual ipv6.addresses '2003:ac18::305/64' connection.autoconnect yes elsebreak
fi
nmcli connection up 'System eth0' &>/dev/null
if [ $? -eq 0 ]thenecho -e "* \E[35m06.\033[0m配置IPv6地址--------------------------\033[33m[ OK$a]\033[0m *"elseecho -e "配置IPv6地址------------------\033[31m[Failed$a]\033[0m"
fi
hostnamectl set-hostname server0.example.com &&
#配置本地邮件服务:
lab smtp-nullclient setup &>/dev/null &&
ssh root@172.25.0.10 </dev/null
lab smtp-nullclient setup
EOF
if [ $? -eq 0 ]thenmainconfigelsebreak
fi
systemctl restart postfix &>/dev/null && echo -e "* \E[35m07.\033[0m配置mail服务--------------------------\033[33m[ OK$a]\033[0m *" || echo -e "配置mail服务------------------\033[31m[Failed$a]\033[0m"
systemctl enable postfix &>/dev/null &&
#Samba发布共享目录:
#Server0端
yum -y install samba &>/dev/null
rpm -q samba &>/dev/null &&
if [ $? -eq 0 ]thenmkdir /common /devops &&setsebool -P samba_export_all_rw onuseradd harry;pdbedit -a harry</dev/null
migwhisk
migwhisk
EOFuseradd kenji;pdbedit -a kenji</dev/null
atenorth
atenorth
EOFuseradd chihiro;pdbedit -a chihiro</dev/null
atenorth
atenorth
EOFsed -i 's/workgroup = MYGROUP/workgroup = STAFF/g' /etc/samba/smb.confecho "[common]
path = /common
hosts allow = 172.25.0.0/24
[devops]
path = /devops
hosts allow = 172.25.0.0/24
write list = chihiro
" >> /etc/samba/smb.confsetfacl -m u:chihiro:rwx /devopselsebreak
fi
systemctl restart smb &>/dev/null
systemctl enable smb &>/dev/null &&
if [ $? -eq 0 ]thenecho -e "* \E[35m08.\033[0m搭建Samba服务-------------------------\033[33m[ OK$a]\033[0m *"elseecho -e "搭建Samba服务-----------------\033[31m[Failed$a]\033[0m"
fi
#Desktop端
ssh root@172.25.0.10 </dev/null
yum -y install samba-client cifs-utils &>/dev/null
mkdir /mnt/dev
if [ $? -eq 0 ]thenecho "//172.25.0.11/devops /mnt/dev cifs user=kenji,pass=atenorth,multiuser,sec=ntlmssp,_netdev 0 0" >> /etc/fstabelsebreak
fi
mount -a
EOF
if [ $? -eq 0 ]thenecho -e "* \E[35m09.\033[0m配置Samba多用户-----------------------\033[33m[ OK$a]\033[0m *"elseecho -e "配置Samba多用户------------------\033[31m[Failed$a]\033[0m"
fi
#配置NFS共享:
#Server0
lab nfskrb5 setup &>/dev/null &&
if [ $? -eq 0 ]thenmkdir -p /public /protected/projectchown ldapuser0 /protected/projectwget -O /etc/krb5.keytab http://classroom.example.com/pub/keytabs/server0.keytab &>/dev/nullecho "/public 172.25.0.0/24(ro)
/protected 172.25.0.0/24(rw,sec=krb5p)
" > /etc/exportselsebreak
fi
systemctl restart nfs-secure-server nfs-server &>/dev/null && echo -e "* \E[35m10.\033[0m搭建NFS服务---------------------------\033[33m[ OK$a]\033[0m *" || echo -e "搭建NFS服务------------------\033[33m[Failed$a]\033[0m"
systemctl enable nfs-secure-server nfs-server &>/dev/null
#desktop0
ssh root@172.25.0.10 </dev/null
lab nfskrb5 setup &>/dev/null &&
if [ $? -eq 0 ]thenmkdir /mnt/nfsmount /mnt/nfssecurewget -O /etc/krb5.keytab http://classroom.example.com/pub/keytabs/desktop0.keytab &>/dev/nullsystemctl restart nfs-secure &>/dev/nullsystemctl enable nfs-secure &>/dev/nullecho "172.25.0.11:/public /mnt/nfsmount nfs _netdev 0 0
172.25.0.11:/protected /mnt/nfssecure nfs sec=krb5p,_netdev 0 0" >> /etc/fstabelsebreak
fi
mount -a &>/dev/null
EOF
if [ $? -eq 0 ]thenecho -e "* \E[35m11.\033[0m挂载NFS服务---------------------------\033[33m[ OK$a]\033[0m *"elseecho -e "挂载NFS服务-----------------\033[31m[Failed$a]\033[0m"
fi
#实现一个Web服务器:
yum -y install httpd &>/dev/null
rpm -q httpd &>/dev/null &&
if [ $? -eq 0 ]thenwget -O /var/www/html/index.html http://classroom.example.com/pub/materials/station.html &>/dev/nullecho "
ServerName server0.example.com
DocumentRoot /var/www/html
" > /etc/httpd/conf.d/vhost.confelsebreak
fi
systemctl restart httpd &>/dev/null && echo -e "* \E[35m12.\033[0m搭建Web服务---------------------------\033[33m[ OK$a]\033[0m *" || echo -e "搭建Web服务------------------\033[33m[Failed$a]\033[0m"
systemctl enable httpd &>/dev/null &&
#配置安全Web服务:
yum -y install mod_ssl &>/dev/null
rpm -q mod_ssl &>/dev/null &&
if [ $? -eq 0 ]then
wget -O /etc/pki/tls/certs/server0.crt http://classroom.example.com/pub/tls/certs/server0.crt &>/dev/null
wget -O /etc/pki/tls/certs/example-ca.crt http://classroom.example.com/pub/example-ca.crt &>/dev/null
wget -O /etc/pki/tls/private/server0.key http://classroom.example.com/pub/tls/private/server0.key &>/dev/nullsed -i 's/#DocumentRoot "\/var\/www\/html"/DocumentRoot "\/var\/www\/html"/g' /etc/httpd/conf.d/ssl.confsed -i 's/#ServerName www.example.com:443/ServerName server0.example.com:443/g' /etc/httpd/conf.d/ssl.confsed -i 's/SSLCertificateFile \/etc\/pki\/tls\/certs\/localhost.crt/SSLCertificateFile \/etc\/pki\/tls\/certs\/server0.crt/g' /etc/httpd/conf.d/ssl.confsed -i 's/SSLCertificateKeyFile \/etc\/pki\/tls\/private\/localhost.key/SSLCertificateKeyFile \/etc\/pki\/tls\/private\/server0.key/g' /etc/httpd/conf.d/ssl.confsed -i 's/#SSLCACertificateFile \/etc\/pki\/tls\/certs\/ca-bundle.crt/SSLCACertificateFile \/etc\/pki\/tls\/certs\/example-ca.crt/g' /etc/httpd/conf.d/ssl.confelsebreak
fi
systemctl restart httpd &>/dev/null && echo -e "* \E[35m13.\033[0m搭建Web.key服务-----------------------\033[33m[ OK$a]\033[0m *" || echo -e "搭建Web.key服务------------------\033[33m[Failed$a]\033[0m"
systemctl enable httpd &>/dev/null
#配置虚拟主机:
if [ $? -eq 0 ]thenmkdir /var/www/virtualwget -O /var/www/virtual/index.html http://classroom.example.com/pub/materials/www.html &>/dev/nulluseradd fleyd;setfacl -m u:fleyd:rwx /var/www/virtualecho "
ServerName www0.example.com
DocumentRoot /var/www/virtual
" >> /etc//httpd/conf.d/vhost.confelsebreak
fi
systemctl restart httpd &>/dev/null && echo -e "* \E[35m14.\033[0m搭建Web.virtual服务-------------------\033[33m[ OK$a]\033[0m *" || echo -e "搭建Web.virtual服务------------------\033[33m[Failed$a]\033[0m"
systemctl enable httpd &>/dev/null
#配置Web内容访问:
if [ $? -eq 0 ]thenmkdir /var/www/html/private
wget -O /var/www/html/private/index.html http://classroom.example.com/pub/materials/private.html &>/dev/nullecho '
Require ip 127.0.0.1 ::1 172.25.0.11
' > /etc/httpd/conf.d/power.confelsebreak
fi
systemctl restart httpd &>/dev/null && echo -e "* \E[35m15.\033[0m搭建Web内容服务-----------------------\033[33m[ OK$a]\033[0m *" || echo -e "搭建Web内容服务------------------\033[33m[Failed$a]\033[0m"
systemctl enable httpd &>/dev/null
#实现动态Web内容:
yum -y install mod_wsgi &>/dev/null
rpm -q mod_wsgi &>/dev/null &&
if [ $? -eq 0 ]thenmkdir /var/www/mywebwget -O /var/www/myweb/webinfo.wsgi http://classroom.example.com/pub/materials/webinfo.wsgi &>/dev/nullecho "Listen 8909
ServerName webapp0.example.com
DocumentRoot /var/www/myweb
WsgiScriptAlias / /var/www/myweb/webinfo.wsgi
" >> /etc/httpd/conf.d/vhost.confsemanage port -a -t http_port_t -p tcp 8909elsebreak
fi
systemctl restart httpd &>/dev/null && echo -e "* \E[35m16.\033[0m搭建动态Web内容-----------------------\033[33m[ OK$a]\033[0m *" || echo -e "搭建动态Web内容------------------\033[33m[Failed$a]\033[0m"
systemctl enable httpd &>/dev/null
#创建一个脚本:
touch foo.sh &&
if [ $? -eq 0 ]thenecho '#!/bin/bash
if [ "$1" = "redhat" ];thenecho "fedora"
elif [ "$1" = "fedora" ];thenecho "redhat"
elseecho "/root/foo.sh redhat|fedora" >&2
fi' > /root/foo.shchmod +x /root/foo.shelsebreak
fi
sh /root/foo.sh &>/dev/null ||
sh /root/foo.sh redhat &>/dev/null &&
sh /root/foo.sh fedora &>/dev/null && echo -e "* \E[35m17.\033[0m创建一个脚本--------------------------\033[33m[ OK$a]\033[0m *" || echo -e "创建一个脚本------------------\033[33m[Failed$a]\033[0m"
#添加用户脚本:
touch /root/batchusers &&
if [ $? -eq 0 ]then wget http://classroom.example.com/pub/materials/userlist &>/dev/nullecho '#!/bin/bash
if [ $# -eq 0 ];thenecho "Usage: /root/batchusers "exit 1
fi
if [ ! -f $1 ];thenecho "Input file not found"exit 2
fi
for i in $(cat $1)
douseradd -s /bin/false $i
done
' > /root/batchuserschmod +x /root/batchuserselsebreak
fi
sh /root/batchusers &>/dev/null ||
sh /root/batchusers wxk &>/dev/null ||
sh /root/batchusers userlist &>/dev/null && echo -e "* \E[35m18.\033[0m脚本创建用户--------------------------\033[33m[ OK$a]\033[0m *" || echo -e "脚本创建用户------------------\033[33m[Failed$a]\033[0m"
#配置网络磁盘iscsi:
#server0
yum -y install targetcli &>/dev/null
rpm -q targetcli &>/dev/null
if [ $? -eq 0 ]thenparted /dev/vdb </dev/null
mklabel gpt
mkpart
wxk
ext4
0
3200
q
EOF
echo "自动设置targetcli:"
echo "Loading..."targetcli </dev/null && echo -e "* \E[35m19.\033[0m配置iscsi服务端-----------------------\033[33m[ OK$a]\033[0m *" || echo -e "配置iscsi服务端------------------\033[33m[Failed$a]\033[0m"
systemctl enable target &>/dev/null
touch part.sh
chmod +x part.sh
echo '#!/bin/bash
parted /dev/sda mktable gpt mkpart primary 0 2200 < part.sh
scp part.sh root@172.25.0.10:/root/ &>/dev/null &&
#desktop0@
ssh root@172.25.0.10 </dev/null
yum -y install iscsi-initiator-utils &>/dev/null
rpm -q iscsi-initiator-utils &>/dev/null
if [ $? -eq 0 ]thenecho "InitiatorName=iqn.2016-02.com.example:desktop0" > /etc/iscsi/initiatorname.iscsi
systemctl restart iscsid &>/dev/null
systemctl enable iscsid &>/dev/null
iscsiadm --mode discoverydb --type sendtargets --portal 172.25.0.11 3260 --discover &>/dev/null
systemctl restart iscsi &>/dev/null
systemctl enable iscsi &>/dev/nullsh part.shmkfs.ext4 /dev/sda1 &>/dev/nullmkdir /mnt/datased -i 's/startup = manual/startup = automatic/g' /var/lib/iscsi/nodes/iqn.2016-02.com.example\:server0/172.25.0.11\,3260\,1/defaultecho "/dev/sda1 /mnt/data ext4 _netdev 0 0" >> /etc/fstabelsebreak
fi
mount -a &>/dev/null
EOF
if [ $? -eq 0 ]thenecho -e "* \E[35m20.\033[0m配置iscsi客户端-----------------------\033[33m[ OK$a]\033[0m *"elseecho -e "配置iscsi客户端-----------------\033[31m[Failed$a]\033[0m"
fi
#配置数据库:
yum -y install mariadb-server &>/dev/null
rpm -q mariadb-server &>/dev/null &&
if [ $? -eq 0 ]thenecho "[mysqld]
skip-networking
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
" > /etc/my.cnfsystemctl restart mariadb &>/dev/nullsystemctl enable mariadb &>/dev/nullmysqladmin -u root password 'atenorth' &>/dev/null
mysql -patenorth </dev/null
create database Contacts;
use Contacts;
grant select on Contacts.* to Raikon@localhost identified by 'atenorth';
delete from mysql.user where password='';
flush privileges;
quit
EOFwget http://classroom.example.com/pub/materials/users.sql &>/dev/null
mysql -patenorth Contacts < users.sql
mysql -patenorth </dev/null
use Contacts;
select name from base where password='solicitous';
select count(*) from base,location where base.name='Barbara' and location.city='Sunnyvale' and base.id=location.id;
quit
EOFelseecho -e "配置mariadb服务----------------\033[31m[Failed$a]\033[0m"
fi
systemctl restart mariadb &>/dev/null && echo -e "* \E[35m21.\033[0m配置mariadb服务-----------------------\033[33m[ OK$a]\033[0m *" ||
echo -e "配置mariadb服务----------------\033[31m[Failed$a]\033[0m"
echo "* --------------自动答题完成!--------------- *"
echo "==============================期待您的再次使用!!==============================="
#!/bin/bash
#===========================================================================
# FileName: RHCSA-AK.aotu
#
# Author : WangXinKun
#
# Created : 17:22,01/08/2019
#===========================================================================
#说明:用前需手动添加一块虚拟磁盘(列:vdc)否则swap分区检测会失败!
cecho () {
echo -e " | \033[1;32mC\033[0m \033[1;33mS\033[0m \033[1;35mD\033[0m \033[1;36mN\033[0m \E[1;35m阿\033[0m \033[1;34m坤\033[0m |"
}echo ' .-"""-. '
echo " / .===. \ "
echo " \/ 6 6 \/ "
echo " ( \___/ ) "
echo " _________ooo__\_____/_____________ "
echo " / \ "cecho
echo " \_______________________ooo________/ "
echo " | | | "
echo " |_ | _| "
echo " | | | "
echo " |__|__| "
echo " /-'Y'-\ "
echo " (__/ \__) "m=!
echo "=====================Oo欢迎使用阿坤脚本,祝您使用愉快oO==========================="
echo -e "* \033[36mOoRHCSA-AK自动答题开始oO\033[0m *"
#配置主机名与ip:
hostnamectl set-hostname server0.example.com
hostname &> 1
for a in $(cat 1)
donmcli connection modify 'System eth0' ipv4.method manual ipv4.addresses '172.25.0.11/24 172.25.0.254' ipv4.dns 172.25.254.254 connection.autoconnect yes
done
nmcli connection up 'System eth0' &>/dev/null
if [ $? -eq 0 ]thenecho -e "* \033[34m01.\033[0m\033[35mIP Service set Successfully$m\033[0m *"elseecho -e "\033[31mError 0:IP.service set Failed$m\033[0m"
fi
#配置Yum源:
if [ $? -eq 0 ];thenrm -rf /etc/yum.repos.d/*yum-config-manager --add http://content.example.com/rhel7.0/x86_64/dvd &>/dev/nullecho "gpgcheck=0" >> /etc/yum.repos.d/content.example.com_rhel7.0_x86_64_dvd.repo
else echo -e "\033[31mError 1:Yum.service set Failed$m\033[0m"
fi
yum repolist &>/dev/null
yum -y install xeyes &>/dev/null && echo -e "* \033[34m02.\033[0m\033[35mYum Service set Successfully$m\033[0m *"
#配置swap分区及其他分区:
if [ $? -eq 0 ];thenparted /dev/vdb < /dev/null
mklabel gpt
mkpart
wxk1
ext3
0
1800
mkpart
wxk2
ext3
1800
2800
q
EOFparted /dev/vdc </dev/null
mktable gpt
mkpart
swap
linux-swap
0
800
q
EOFvgcreate -s 1M swapvg /dev/vdc1 &>/dev/nulllvcreate -l 512 -n swapvo swapvg &>/dev/nullmkswap /dev/swapvg/swapvo &>/dev/nullecho "/dev/swapvg/swapvo swap swap defaults 0 0" >> /etc/fstab
swapon -a &>/dev/null &&mkdir /mnt/databasevgcreate -s 16M datastore /dev/vdb1 &>/dev/nulllvcreate -l 50 -n database datastore &>/dev/nullmkfs.ext3 /dev/datastore/database &>/dev/nullecho "/dev/datastore/database /mnt/database ext3 defaults 0 0" >> /etc/fstab
mount -a &>/dev/null &&mkdir /vovgcreate systemvg /dev/vdb2 &>/dev/nulllvcreate -L 200M -n vo systemvg &>/dev/nullmkfs.ext3 /dev/systemvg/vo &>/dev/nulllvextend -L 300M /dev/systemvg/vo &>/dev/nullresize2fs /dev/systemvg/vo &>/dev/nullecho "/dev/systemvg/vo /vo ext3 defaults 0 0" >> /etc/fstab
mount -a &>/dev/null
elseecho -e "\033[31mError 2:Parted.service set Failed$m\033[0m"
fi
mount -a &>/dev/null &&echo -e "* \033[34m03.\033[0m\033[35mParted Service set Successfully$m\033[0m *"
#创建用户及分组:
if [ $? -eq 0 ]thengroupadd adminuseruseradd -G adminuser natashauseradd -G adminuser harryuseradd -s /sbin/nologin sarahecho flectrag | passwd --stdin natasha &>/dev/nullecho flectrag | passwd --stdin harry &>/dev/nullecho flectrag | passwd --stdin sarah &>/dev/null
elseecho -e "\033[31mError 3:Useradd and Groupadd Service sets Failed$m\033[0m"
fiecho "natasha harry sarah" > userlist
for i in $(cat userlist)
doif [ ! -e /home/$i ]thenkillall RHCSA-AK.shexit 604fi
done
id natasha &>/dev/null &&id harry &>/dev/null &&id sarah &>/dev/null &&cp /etc/fstab /var/tmp/fstab && #配置/var/tmp/fstab的权限 setfacl -m u:natasha:rwx /var/tmp/fstab &&
setfacl -m u:harry:- /var/tmp/fstab&&echo -e "* \033[34m04.\033[0m\033[35mUGadd Service set Successfully$m\033[0m *"
#配置一个cron任务:
if [ $? -eq 0 ]thensystemctl restart crondecho "23 14 * * * natasha /bin/echo hiya" >> /etc/crontab; systemctl restart crondsystemctl enable crondecho -e "* \033[34m05.\033[0m\033[35mCrond Service set Successfully$m\033[0m *"elseecho -e "\033[31mError 4: Crond.service set Failed$m\033[0m"
fi
#创建一个共享目录:
if [ $? -eq 0 ]thenmkdir /home/adminschown :adminuser /home/adminschmod 2770 /home/adminsecho -e "* \033[34m06.\033[0m\033[35mSBit Service set Successfully$m\033[0m *"elseecho -e "\033[31mError 5: Sticky Bit Service set Failed$m\033[0m"
fi
#绑定到外部验证服务:
if [ $? -eq 0 ];then
yum -y install sssd &> /dev/null
rpm -q sssd &>/dev/null &&
authconfig \
--enableldap \
--enablekrb5 \
--disableldapauth \
--enableldaptls \
--ldapserver="classroom.example.com" \
--ldapbasedn="dc=example,dc=com" \
--ldaploadcacert=http://172.25.254.254/pub/example-ca.crt \
--krb5realm="EXAMPLE.COM" \
--krb5kdc="classroom.example.com" \
--krb5adminserver="classroom.example.com" \
--updateelseecho -e "\033[31mError 6: LDAP.service set Failed$m\033[0m"
fi
systemctl restart sssd &>/dev/null && echo -e "* \033[34m07.\033[0m\033[35mLDAP Service set Successfully$m\033[0m *" || echo -e "\033[31mError 6: LDAP.service set Failed$m\033[0m"
systemctl enable sssd &>/dev/null &&
#autofs配置:
mkdir /home/guests &&
if [ $? -eq 0 ]thenyum -y install autofs &>/dev/nullrpm -q autofs &>/dev/null &&echo "/home/guests /etc/auto.ldap" >>/etc/auto.masterecho "* 172.25.254.254:/home/guests/&">>/etc/auto.ldap
fi
systemctl restart autofs &>/dev/null && echo -e "* \033[34m08.\033[0m\033[35mAutofs Service set Successfully$m\033[0m *" || echo -e "\033[31mError 7: Autofs.service set Failed$m\033[0m"
systemctl enable autofs &>/dev/null &&
#配置NTP网络时间客户端:
if [ $? -eq 0 ]thenecho "# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.rhel.pool.ntp.org iburst
#server 1.rhel.pool.ntp.org iburst
#server 2.rhel.pool.ntp.org iburst
#server 3.rhel.pool.ntp.org iburst
server classroom.example.com iburst
# Ignore stratum in source selection.
stratumweight 0# Record the rate at which the system clock gains/losses time.
driftfile /var/lib/chrony/drift# Enable kernel RTC synchronization.
rtcsync# In first three updates step the system clock instead of slew
# if the adjustment is larger than 10 seconds.
makestep 10 3# Allow NTP client access from local network.
#allow 192.168/16# Listen for commands only on localhost.
bindcmdaddress 127.0.0.1
bindcmdaddress ::1# Serve time even if not synchronized to any NTP server.
#local stratum 10keyfile /etc/chrony.keys# Specify the key used as password for chronyc.
commandkey 1# Generate command key if missing.
generatecommandkey# Disable logging of client accesses.
noclientlog# Send a message to syslog if a clock adjustment is larger than 0.5 seconds.
logchange 0.5logdir /var/log/chrony
#log measurements statistics tracking
" > /etc/chrony.confelseecho -e "\033[31mError 8: NTP.service set Failed$m\033[0m"
fi
systemctl restart chronyd &>/dev/null && echo -e "* \033[34m09.\033[0m\033[35mNTP Service set Successfully$m\033[0m *" || echo -e "\033[31mError 8: NTP.service set Failed$m\033[0m"
systemctl enable chronyd &>/dev/null &&
#查找文件:
if [ $? -eq 0 ]thenmkdir /root/findfilesfind / -user student -type f -exec cp -p {} /root/findfiles/ \; &>/dev/nullelseecho -e "\033[31mError 9: Find.service set Failed$m\033[0m"
fi
if [ $? -eq 0 ]thenecho -e "* \033[34m10.\033[0m\033[35mFind Service set Successfully$m\033[0m *"elsebreak
fi
#配置一个用户账户:
useradd -u 3456 alex;echo 'flectrag' | passwd --stdin alex &>/dev/null &&
if [ $? -eq 0 ]thenif [ ! -e /home/alex ]thencontinueecho -e "\033[31mError 10: Useradd.service set Failed$m\033[0m"fielseecho -e "* \033[34m11.\033[0m\033[35mUser Service set Successfully$m\033[0m *"
fi
#查找字符串:
grep 'seismic' /usr/share/dict/words > /root/wordlist && echo -e "* \033[34m12.\033[0m\033[35mGrep Service set Successfully$m\033[0m *" || echo -e "\033[31mError 11: Grep.service set Failed$m\033[0m"
#创建一个归档:
tar Pcjf /root/backup.tar.bz2 /usr/local/ && echo -e "* \033[34m13.\033[0m\033[35mTar Service set Successfully$m\033[0m *" || echo -e "\033[31mError 12: Tar.service set Failed$m\033[0m"
#安装内核升级:
if [ $? -eq 0 ]thenwget http://classroom.example.com/content/rhel7.0/x86_64/errata/Packages/kernel-3.10.0-123.1.2.el7.x86_64.rpm &>/dev/nullelseecho -e "\033[31mError 13: Kernelupdate.service set Failed$m\033[0m"
fi
rpm -ivh kernel-3.10.0-123.1.2.el7.x86_64.rpm &>/dev/null && echo -e "* \033[34m14.\033[0m\033[35mKernel Service set Successfully$m\033[0m *"
echo "* --------------自动答题完成!--------------- *"
echo "==============================期待您的再次使用!!==============================="
echo "5秒后重启$m"
sleep 5
reboot
职业规划:
创作规划: