做一个脚本练习题不容易,但是出一道好的shell脚本题更加不容易!所以大家还是珍惜阿铭出的每一道shell脚本练习题吧!
今天红帽官方发了bash的漏洞,其实这个漏洞已经好久啦,那些大牛级别的黑客早就玩的不想玩了,所以报出来,给自己找点乐子,因为他们太喜欢看各大厂商手忙脚乱修漏洞的样子了。其实,官方虽然说升级到指定版本会修复漏洞,但实际上,我们公司的安全部门的兄弟告诉我们,漏洞还在,还能够绕过官方的补丁,目前百度加速乐已经做了针对性的防护。腾讯这边也在夜以继日地想解决办法。
好了,漏洞总归是能补上的。那现在,即使说漏洞还能绕过,但我们也应该需要把bash版本升级一下。所以,阿铭给你出的题目是:写一个shell脚本,先判断一下你linux的版本和bash版本,然后看看是否需要升级,若是升级,则使用yum直接升级,否则输出一条日志,告之不需要升级。
参考信息:我们要保证对应版本的CentOS里的bash版本不低于以下版本。假设我们只判断centos5和centos6两种系统。
今天红帽官方发了bash的漏洞,其实这个漏洞已经好久啦,那些大牛级别的黑客早就玩的不想玩了,所以报出来,给自己找点乐子,因为他们太喜欢看各大厂商手忙脚乱修漏洞的样子了。其实,官方虽然说升级到指定版本会修复漏洞,但实际上,我们公司的安全部门的兄弟告诉我们,漏洞还在,还能够绕过官方的补丁,目前百度加速乐已经做了针对性的防护。腾讯这边也在夜以继日地想解决办法。
好了,漏洞总归是能补上的。那现在,即使说漏洞还能绕过,但我们也应该需要把bash版本升级一下。所以,阿铭给你出的题目是:写一个shell脚本,先判断一下你linux的版本和bash版本,然后看看是否需要升级,若是升级,则使用yum直接升级,否则输出一条日志,告之不需要升级。
参考信息:我们要保证对应版本的CentOS里的bash版本不低于以下版本。假设我们只判断centos5和centos6两种系统。
- Red Hat Enterprise Linux 7 - bash-4.2.45-5.el7_0.2
- Red Hat Enterprise Linux 6 - bash-4.1.2-15.el6_5.1
- Red Hat Enterprise Linux 5 - bash-3.2-33.el5.1
0
本帖最后由 Louis 于 2014-9-26 16:37 编辑
思路:
依据系统版本查看bash对应版本是否符合要求,如符合,记录版本已正确到日志;如不符合,更新。
更新后再次检验版本是否符合要求,如符合,记录更新成功到日志,如还不符合,记录更新失败信息到日志。
2014/09/26 16:35修改:
上面脚本判断系统版本的if条件错误,应该用-eq,错用成了-ge。
第8行,if [ $os_release -ge 6 ]; then,改为:if [ $os_release -eq 6 ]; then;
第19行,elif [ $os_release -ge 5 ]; then,改为elif [ $os_release -eq 5 ]; then。
- #!/bin/bash
- ## This script is for update bash the right release.
- ## Writed by Louis at 2014/09/25 20:30
- os_release=`head -1 /etc/issue|awk -F. '{print $1}'|awk '{print $3}'`
- bash_release=`rpm -q bash|sed 's/.x86_64//;s/.i686//'`
- if [ $os_release -ge 6 ]; then
- if [ "$bash_release" != "bash-4.1.2-15.el6_5.1" ]; then
- yum update -y bash
- if [ "$bash_release" == "bash-4.1.2-15.el6_5.1" ]; then
- echo "Bash has been updated succeed!" > /tmp/update.log
- else
- echo "Update failed.please check it out." > /tmp/update.log
- fi
- else
- echo "Bash release is the newest one. Do not need update." > /tmp/update.log
- fi
- elif [ $os_release -ge 5 ]; then
- if [ "$bash_release" != "bash-3.2-33.el5.1" ]; then
- yum update -y bash
- if [ "$bash_release" == "bash-4.1.2-15.el6_5.1" ]; then
- echo "Bash has been updated succeed!" > /tmp/update.log
- else
- echo "Update failed.please check it out." > /tmp/update.log
- fi
- else
- echo "Bash release is the newest one. Do not need update." > /tmp/update.log
- fi
- else
- echo "Your system is not release 5 or 6,please check it out."
- fi
依据系统版本查看bash对应版本是否符合要求,如符合,记录版本已正确到日志;如不符合,更新。
更新后再次检验版本是否符合要求,如符合,记录更新成功到日志,如还不符合,记录更新失败信息到日志。
2014/09/26 16:35修改:
上面脚本判断系统版本的if条件错误,应该用-eq,错用成了-ge。
第8行,if [ $os_release -ge 6 ]; then,改为:if [ $os_release -eq 6 ]; then;
第19行,elif [ $os_release -ge 5 ]; then,改为elif [ $os_release -eq 5 ]; then。
0
本帖最后由 游夜 于 2014-9-25 23:01 编辑
- #!/bin/bash
- os_ver=cat /etc/redhat-release|awk -F "." '{print $1}'|awk '{print $3}' #获取linux版本号,并进行处理
- bash_ver= rpm -qa bash|sed 's/.i686//g'|sed 's/.x86_64//g' #获取bash版本号,并进行处理
- case $os_ver in #判断linux版本为5还是6,并跳转到相应的command进行bash版本的判断
- 6)
- if [ "$bash_ver" != "bash-4.1.2-15.el6_5.1" ]#判断的bash的版本是否为bash-4.1.2-15.el6_5.1,是则升级,不是则提示不需要升级
- then
- yum update -y bash
- else
- echo "Bash not need to update!"
- fi
- ;;
- 5)
- if [ "$bash_ver" != "bash-3.2-33.el5.1" ]#判断的bash的版本是否为bash-3.2-33.el5.1,是则升级,不是则提示不需要升级
- then
- yum update -y bash
- else
- echo "Bash not need to update!"
- fi
- ;;
- esac
0
本帖最后由 齐天大圣 于 2014-9-26 10:03 编辑
-eq好于-ge,这样可以精确匹配。如我我版本是6,if符合条件,else还是符合条件
Louis 发表于 2014-9-25 20:45
思路:
依据系统版本查看bash对应版本是否符合要求,如符合,记录版本已正确到日志;如不符合,更新。
更 ...
-eq好于-ge,这样可以精确匹配。如我我版本是6,if符合条件,else还是符合条件
0
本帖最后由 陈沛 于 2014-9-26 13:58 编辑
/*****************************************************************************/
本shell脚本只是实现思路,语法与简单实现,没有进行详细的测试,可能会有问题
- #/bin/bash
- # 2014-09-26
- # chenpei
- # bash version update
- # Linux bash update
- bash_update() {
- read -p "The input "Y OR N" : " Y_N
- case $Y_N in
- 5)
- echo "正在升级。"
- yum update -y bash
- ;;
- *)
- echo "输入非Y选项,放弃升级。"
- ;;
- esac
- }
- # Linux bash update to compare
- bash_update_compare() {
- tmp=`rpm -qf /bin/bash | awk -F'.' '{printf $NF}'`
- #Linux bash version
- bash_version=`rpm -qf /bin/bash | sed "s#\.${tmp}##g"`
- #Whether to upgrade
- #由于不能低于指定版本(进行简单的版本号比较)
- #主版本号比较
- up_bash=`echo $1 | awk -F'[-]' '{print $2}'`
- old_bash=`echo $bash_version | awk -F'[-]' '{print $2}'`
- if [ `echo $old_bash | awk -F'.' '{print $1}'` -gt `echo $up_bash | awk -F'.' '{print $1}'` ] ; then
- bash_update
- return 1;
- elif [ `echo $old_bash | awk -F'.' '{print $2}'` -gt `echo $up_bash | awk -F'.' '{print $2}'` ] ; then
- bash_update
- return 1;
- elif [ `echo $old_bash | awk -F'.' '{print $3}'` -gt `echo $up_bash | awk -F'.' '{print $3}'` ] ; then
- bash_update
- return 1;
- fi
- #次版本号比较
- up_bash=`echo $1 | awk -F'[-]' '{print $3}'`
- old_bash=`echo $bash_version | awk -F'[-]' '{print $3}'`
- if [ `echo $old_bash | awk -F'.' '{print $1}'` -gt `echo $up_bash | awk -F'.' '{print $1}'` ] ; then
- bash_update
- return 1;
- fi
- echo "bash版本无需升级。"
- }
- # Linux vsersion
- version=`cat /etc/issue | sed 's#[^0-9/.]##g' | awk -F'.' '{print $1}'`
- # Linux system selection
- case $version in
- 5) #Red Hat Enterprise Linux 5 - bash-3.2-33.el5.1
- bash_update_compare bash-3.2-33.el5.1
- ;;
- 6) #Red Hat Enterprise Linux 6 - bash-4.1.2-15.el6_5.1
- bash_update_compare bash-4.1.2-15.el6_5.1
- ;;
- *)
- echo "您使用的Linux系统版本过高或高低无法进行测试与升级。"
- ;;
- esac
/*****************************************************************************/
本shell脚本只是实现思路,语法与简单实现,没有进行详细的测试,可能会有问题
0
#bash update
os=`cat /etc/redhat-release |awk '{print $3}'|awk -F . '{print $1}'`
bash=`rpm -qa bash |sed 's/.x86_64//g' |sed 's/.i686//g'`
if [ $os -ge 5 -o $os -le 6 ];then
if [ '$bash' != 'bash-4.1.2-15.el6_5.1' -o '$bash' != 'bash-3.2-33.el5.1' ];then
yum update -y bash
else
echo "you bash not update"
fi
fi
~
os=`cat /etc/redhat-release |awk '{print $3}'|awk -F . '{print $1}'`
bash=`rpm -qa bash |sed 's/.x86_64//g' |sed 's/.i686//g'`
if [ $os -ge 5 -o $os -le 6 ];then
if [ '$bash' != 'bash-4.1.2-15.el6_5.1' -o '$bash' != 'bash-3.2-33.el5.1' ];then
yum update -y bash
else
echo "you bash not update"
fi
fi
~
0
本帖最后由 soar 于 2014-9-26 22:41 编辑
#!/bin/bash
os=`head -1 /etc/issue | awk '{print $3}'| awk -F "." '{print $1}'`
bash_version=`rpm -q bash | sed 's/.i686//'`
if [ $os -eq 6 ]
then
if [ $base_version = bash-4.1.2-15.el6_5.1 ]
then
echo "your bash needn't to update">./tmp/bashupdate.log
else
/usr/bin/yum update -y bash
fi
elif [ $os -eq 5 ]
then
if [ $bash_version = bash-3.2-33.el5.1 ]
then
echo "your bash needn't to update">./tmp/bashupdate.log
else
/usr/bin/yum update -y bash
fi
else
echo "your os version is not 5 or 6,do nothing!!"
fi
#!/bin/bash
os=`head -1 /etc/issue | awk '{print $3}'| awk -F "." '{print $1}'`
bash_version=`rpm -q bash | sed 's/.i686//'`
if [ $os -eq 6 ]
then
if [ $base_version = bash-4.1.2-15.el6_5.1 ]
then
echo "your bash needn't to update">./tmp/bashupdate.log
else
/usr/bin/yum update -y bash
fi
elif [ $os -eq 5 ]
then
if [ $bash_version = bash-3.2-33.el5.1 ]
then
echo "your bash needn't to update">./tmp/bashupdate.log
else
/usr/bin/yum update -y bash
fi
else
echo "your os version is not 5 or 6,do nothing!!"
fi
0
本帖最后由 程城 于 2014-9-28 22:56 编辑
#!/bin/bash
#•Red Hat Enterprise Linux 7 - bash-4.2.45-5.el7_0.2
#•Red Hat Enterprise Linux 6 - bash-4.1.2-15.el6_5.1
#•Red Hat Enterprise Linux 5 - bash-3.2-33.el5.1
system_release=`head -n 1 /etc/issue |awk '{print $3}'|awk -F '.' '{print $1}'`
bash_release=`bash -version | head -n 1 |awk '{print $4}'|sed 's/(.*//g'`
case $system_release in
5)
a=`echo $bash_release |awk -F '.' '{print $1}'`
b=`echo $bash_release |awk -F '.' '{print $2}'`
c=`echo $bash_release |awk -F '.' '{print $3}'`
if [ $a lt 3 ];then
echo "warning ! you should update your bash up to bash-3.3-33"
elif [ $a gt 3 ];then
echo "your bash_release is big then bash-3.2-33,you should not update"
else
if [ $b lt 2 ];then
echo "warning ! you should update your bash up to bash-3.2-33"
elif [ $b gt 2 ];then
echo "your bash_release is big then bash-3.2-33,you should not update"
else
if [ $c le 0 ] ;then
echo "warning ! you should update your bash up to bash-3.2-33"
else
echo "your bash_release is big then bash-3.2-33,you should not update"
fi
fi
fi
;;
6)
a=`echo $bash_release |awk -F '.' '{print $1}'`
b=`echo $bash_release |awk -F '.' '{print $2}'`
c=`echo $bash_release |awk -F '.' '{print $3}'`
if [ $a lt 4 ];then
echo "warning ! you should update your bash up to bash-3.3-33"
elif [ $a gt 4 ];then
echo "your bash_release is big then bash-3.2-33,you should not update"
else
if [ $b lt 1 ];then
echo "warning ! you should update your bash up to bash-3.2-33"
elif [ $b gt 1 ];then
echo "your bash_release is big then bash-3.2-33,you should not update"
else
if [ $c le 2 ] ;then
echo "warning ! you should update your bash up to bash-3.2-33"
else
echo "your bash_release is big then bash-3.2-33,you should not update"
fi
fi
fi
;;
*)
echo "you system errors!"
;;
esac
#!/bin/bash
#•Red Hat Enterprise Linux 7 - bash-4.2.45-5.el7_0.2
#•Red Hat Enterprise Linux 6 - bash-4.1.2-15.el6_5.1
#•Red Hat Enterprise Linux 5 - bash-3.2-33.el5.1
system_release=`head -n 1 /etc/issue |awk '{print $3}'|awk -F '.' '{print $1}'`
bash_release=`bash -version | head -n 1 |awk '{print $4}'|sed 's/(.*//g'`
case $system_release in
5)
a=`echo $bash_release |awk -F '.' '{print $1}'`
b=`echo $bash_release |awk -F '.' '{print $2}'`
c=`echo $bash_release |awk -F '.' '{print $3}'`
if [ $a lt 3 ];then
echo "warning ! you should update your bash up to bash-3.3-33"
elif [ $a gt 3 ];then
echo "your bash_release is big then bash-3.2-33,you should not update"
else
if [ $b lt 2 ];then
echo "warning ! you should update your bash up to bash-3.2-33"
elif [ $b gt 2 ];then
echo "your bash_release is big then bash-3.2-33,you should not update"
else
if [ $c le 0 ] ;then
echo "warning ! you should update your bash up to bash-3.2-33"
else
echo "your bash_release is big then bash-3.2-33,you should not update"
fi
fi
fi
;;
6)
a=`echo $bash_release |awk -F '.' '{print $1}'`
b=`echo $bash_release |awk -F '.' '{print $2}'`
c=`echo $bash_release |awk -F '.' '{print $3}'`
if [ $a lt 4 ];then
echo "warning ! you should update your bash up to bash-3.3-33"
elif [ $a gt 4 ];then
echo "your bash_release is big then bash-3.2-33,you should not update"
else
if [ $b lt 1 ];then
echo "warning ! you should update your bash up to bash-3.2-33"
elif [ $b gt 1 ];then
echo "your bash_release is big then bash-3.2-33,you should not update"
else
if [ $c le 2 ] ;then
echo "warning ! you should update your bash up to bash-3.2-33"
else
echo "your bash_release is big then bash-3.2-33,you should not update"
fi
fi
fi
;;
*)
echo "you system errors!"
;;
esac
0
- #!/bin/bash
- #name:check_bash.sh
- #author:ww
- #check bash version
- os_version=`cat /etc/issue | grep release | awk '{print $3}' | awk -F '.' '{print $1}'`
- bash_version=`rpm -qa bash | awk -F '-' '{print $2"-"$3}'|cut -d '.' -f 1,2,3,4,5`
- echo $os_version $bash_version
- case $os_version in
- 5)
- if [ "$bash_version" == "3.2-33.el5.1" ]
- then
- echo "the bash version is lastest"
- else
- yum update -y bash
- fi
- ;;
- 6)
- if [ "$bash_version" == "4.1.2-15.el6_5.1" ]
- then
- echo "the bash version is lastest"
- else
- yum update -y bash
- fi
- ;;
- 7)
- if [ "$bash_version" == "4.2.45-5.el7_0.2" ]
- then
- echo "the bash version is lastest"
- else
- yum update -y bash
- fi
- ;;
- *)
- echo "i cant get the os version"
- ;;
- esac
0
#! /bin/bash
os=`head -1 /etc/issue |awk '{print $3}'|awk -F'.' '{print $1}'`
bash_ver=`rpm -q bash|sed 's/.x86_64//g'||'s/.i686//g'`
if [ $os -lt 6 ] ;then
if [ $bash_ver != "bash-3.2-33.el5.1" ]
then
echo "bash update now!"
yum update bash -y
else
echo "bash don't need to update!" > /tmp/update.log
fi
elif [ $os -ge 6 ] && [$os -lt 7 ];then
if [ $bash_ver != "bash-4.1.2-15.el6_5.1" ]
then
echo "bash update now!"
yum update bash -y
else
echo "bash don't need to update!" > /tmp/update.log
fi
else
if [ $bash_ver != "bash-4.2.45-5.el7_0.2" ]
then
echo "bash update now!"
yum update bash -y
else
echo "bash don't need to update!" > /tmp/update.log
fi
fi
os=`head -1 /etc/issue |awk '{print $3}'|awk -F'.' '{print $1}'`
bash_ver=`rpm -q bash|sed 's/.x86_64//g'||'s/.i686//g'`
if [ $os -lt 6 ] ;then
if [ $bash_ver != "bash-3.2-33.el5.1" ]
then
echo "bash update now!"
yum update bash -y
else
echo "bash don't need to update!" > /tmp/update.log
fi
elif [ $os -ge 6 ] && [$os -lt 7 ];then
if [ $bash_ver != "bash-4.1.2-15.el6_5.1" ]
then
echo "bash update now!"
yum update bash -y
else
echo "bash don't need to update!" > /tmp/update.log
fi
else
if [ $bash_ver != "bash-4.2.45-5.el7_0.2" ]
then
echo "bash update now!"
yum update bash -y
else
echo "bash don't need to update!" > /tmp/update.log
fi
fi
0
本帖最后由 陌懒 于 2014-9-28 17:31 编辑
#!/bin/bash
#升级BASH版本
os=`cat /etc/issue|awk '{print $3}'|head -n 1|cut -d '.' -f 1`
bash=`rpm -q bash|cut -d '-' -f 2,3`
#Centos5的bash版本判断
if [ $os == 5 ] ;then
echo "The system is Red Hat Enterprise Linux 5" >/tmp/update5.log
if [ $bash == 3.2-33.el5.1 ] ;then
echo "The Red Hat Enterprise Linux 5 system has been updated." >>/tmp/update5.log
else yum update -y bash
echo "The Red Hat Enterprise Linux 5 system update succeed!" >>/tmp/update5.log
fi
fi
#Centos6的版本判断
if [ $os == 6 ] ;then
echo "The system is Red Hat Enterprise Linux 6" >/tmp/update6.log
if [ $bash == 4.1.2-15.el6_5.1 ] ;then
echo "The Red Hat Enterprise Linux 6 system can't update." >>/tmp/update6.log
else yum update -y bash
echo "The Red Hat Enterprise Linux 6 system update succeed!" >>/tmp/update6.log
fi
fi
#!/bin/bash
#升级BASH版本
os=`cat /etc/issue|awk '{print $3}'|head -n 1|cut -d '.' -f 1`
bash=`rpm -q bash|cut -d '-' -f 2,3`
#Centos5的bash版本判断
if [ $os == 5 ] ;then
echo "The system is Red Hat Enterprise Linux 5" >/tmp/update5.log
if [ $bash == 3.2-33.el5.1 ] ;then
echo "The Red Hat Enterprise Linux 5 system has been updated." >>/tmp/update5.log
else yum update -y bash
echo "The Red Hat Enterprise Linux 5 system update succeed!" >>/tmp/update5.log
fi
fi
#Centos6的版本判断
if [ $os == 6 ] ;then
echo "The system is Red Hat Enterprise Linux 6" >/tmp/update6.log
if [ $bash == 4.1.2-15.el6_5.1 ] ;then
echo "The Red Hat Enterprise Linux 6 system can't update." >>/tmp/update6.log
else yum update -y bash
echo "The Red Hat Enterprise Linux 6 system update succeed!" >>/tmp/update6.log
fi
fi
0
#!/bin/bash
#•Red Hat Enterprise Linux 7 - bash-4.2.45-5.el7_0.2
#•Red Hat Enterprise Linux 6 - bash-4.1.2-15.el6_5.1
#•Red Hat Enterprise Linux 5 - bash-3.2-33.el5.1
system_release=`head -n 1 /etc/issue |awk '{print $3}'|awk -F '.' '{print $1}'`
bash_release=`bash -version | head -n 1 |awk '{print $4}'|sed 's/(.*//g'`
case $system_release in
5)
a=`echo $bash_release |awk -F '.' '{print $1}'`
b=`echo $bash_release |awk -F '.' '{print $2}'`
c=`echo $bash_release |awk -F '.' '{print $3}'`
if [ $a lt 3 ];then
echo "warning ! you should update your bash up to bash-3.3-33"
elif [ $a gt 3 ];then
echo "your bash_release is big then bash-3.2-33,you should not update"
else
if [ $b lt 2 ];then
echo "warning ! you should update your bash up to bash-3.2-33"
elif [ $b gt 2 ];then
echo "your bash_release is big then bash-3.2-33,you should not update"
else
if [ $c le 0 ] ;then
echo "warning ! you should update your bash up to bash-3.2-33"
else
echo "your bash_release is big then bash-3.2-33,you should not update"
fi
fi
fi
;;
6)
a=`echo $bash_release |awk -F '.' '{print $1}'`
b=`echo $bash_release |awk -F '.' '{print $2}'`
c=`echo $bash_release |awk -F '.' '{print $3}'`
if [ $a lt 4 ];then
echo "warning ! you should update your bash up to bash-3.3-33"
elif [ $a gt 4 ];then
echo "your bash_release is big then bash-3.2-33,you should not update"
else
if [ $b lt 1 ];then
echo "warning ! you should update your bash up to bash-3.2-33"
elif [ $b gt 1 ];then
echo "your bash_release is big then bash-3.2-33,you should not update"
else
if [ $c le 2 ] ;then
echo "warning ! you should update your bash up to bash-3.2-33"
else
echo "your bash_release is big then bash-3.2-33,you should not update"
fi
fi
fi
;;
*)
echo "you system errors!"
;;
esac
#•Red Hat Enterprise Linux 7 - bash-4.2.45-5.el7_0.2
#•Red Hat Enterprise Linux 6 - bash-4.1.2-15.el6_5.1
#•Red Hat Enterprise Linux 5 - bash-3.2-33.el5.1
system_release=`head -n 1 /etc/issue |awk '{print $3}'|awk -F '.' '{print $1}'`
bash_release=`bash -version | head -n 1 |awk '{print $4}'|sed 's/(.*//g'`
case $system_release in
5)
a=`echo $bash_release |awk -F '.' '{print $1}'`
b=`echo $bash_release |awk -F '.' '{print $2}'`
c=`echo $bash_release |awk -F '.' '{print $3}'`
if [ $a lt 3 ];then
echo "warning ! you should update your bash up to bash-3.3-33"
elif [ $a gt 3 ];then
echo "your bash_release is big then bash-3.2-33,you should not update"
else
if [ $b lt 2 ];then
echo "warning ! you should update your bash up to bash-3.2-33"
elif [ $b gt 2 ];then
echo "your bash_release is big then bash-3.2-33,you should not update"
else
if [ $c le 0 ] ;then
echo "warning ! you should update your bash up to bash-3.2-33"
else
echo "your bash_release is big then bash-3.2-33,you should not update"
fi
fi
fi
;;
6)
a=`echo $bash_release |awk -F '.' '{print $1}'`
b=`echo $bash_release |awk -F '.' '{print $2}'`
c=`echo $bash_release |awk -F '.' '{print $3}'`
if [ $a lt 4 ];then
echo "warning ! you should update your bash up to bash-3.3-33"
elif [ $a gt 4 ];then
echo "your bash_release is big then bash-3.2-33,you should not update"
else
if [ $b lt 1 ];then
echo "warning ! you should update your bash up to bash-3.2-33"
elif [ $b gt 1 ];then
echo "your bash_release is big then bash-3.2-33,you should not update"
else
if [ $c le 2 ] ;then
echo "warning ! you should update your bash up to bash-3.2-33"
else
echo "your bash_release is big then bash-3.2-33,you should not update"
fi
fi
fi
;;
*)
echo "you system errors!"
;;
esac
0
本帖最后由 cmzsteven 于 2015-2-10 16:37 编辑
- #!/bin/bash
- sys_ver=`cat /etc/centos-release|awk '{print $3}'|awk -F '.' '{print $1}'`
- bash_path=`which bash`
- bash_ver=`rpm -qf $bash_path`
- bash_ver=`echo $bash_ver|sed 's/-/./g'`
- bv1=`echo $bash_ver|awk -F '.' '{print $2}'`
- bv2=`echo $bash_ver|awk -F '.' '{print $3}'`
- bv3=`echo $bash_ver|awk -F '.' '{print $4}'`
- bv4=`echo $bash_ver|awk -F '.' '{print $5}'`
- function update_bash()
- {
- if [ $1 -eq 1 ];then
- yum clean all
- yum makecache
- yum -y update bash
- else
- echo "The bash on your system is not need to update!"
- fi
- }
- function test_verion_5()
- {
- test_result=0
- if [ $1 -lt 3 ]; then
- test_rerult=1
- else
- if [ $2 -lt 2 ]; then
- test_result=1
- else
- if [ $3 -lt 33 ]; then
- test_result=1
- fi
- fi
- fi
- update_bash $test_result
- }
- function test_version_6()
- {
- test_result=0
- if [ $1 -lt 4 ]; then
- test_rerult=1
- else
- if [ $2 -lt 1 ]; then
- test_result=1
- else
- if [ $3 -lt 2 ]; then
- test_result=1
- else
- if [ $4 -lt 15 ]; then
- test_result=1
- fi
- fi
- fi
- fi
- update_bash $test_result
- }
- function test_version_7()
- {
- test_result=0
- if [ $1 -lt 4 ]; then
- test_rerult=1
- else
- if [ $2 -lt 2 ]; then
- test_result=1
- else
- if [ $3 -lt 45 ]; then
- test_result=1
- else
- if [ $4 -lt 5 ]; then
- test_result=1
- fi
- fi
- fi
- fi
- update_bash $test_result
- }
- case $sys_ver in
- 5)
- test_version_5 $bv1 $bv2 $bv3
- ;;
- 6)
- test_version_6 $bv1 $bv2 $bv3 $bv4
- ;;
- 7)
- test_version_7 $bv1 $bv2 $bv3 $bv4
- ;;
- esac
0
#!/bin/bash LINVERC=`lsb_release -a` BACVERC=`/bin/bash -version` let LINVER=`echo "$LINVERC"|grep 'Release' |awk -F' ' '{print $2}'|awk -F'.' '{print $1}'` BACVER=`echo "$BACVERC"|head -1|awk -F' ' '{print $4}'` echo "$BACVER" > BACVER.log echo "4.1.2(1)-release" > BACVER6.log b6=`md5sum BACVER6.log > BACVER6.md5` echo "3.2.33(1)-release" > BACVER5.log b5=`md5sum BACVER5.log> BACVER5.md5` if [ $LINVER -eq 5 ];then LINST=`echo "$BACVER" > BACVER5.log` LINST5=` md5sum BACVER5.log >BACVER5.md5` b5=`md5sum -c --status BACVER5.md5` st=`echo $?` if [ $st -eq 0 ];then echo " linux version is 5 , it is not need update" else echo "yum intall 5" fi fi if [ $LINVER -eq 6 ];then LINST=`echo "$BACVER" > BACVER6.log` LINST6=`md5sum BACVER6.log >BACVER6.md5` bc=`md5sum -c --status BACVER6.md5` st=`echo $?` if [ $st -eq 0 ];then echo " linux version is 6 , it is not need update" else echo "yum intall 6" fi fi
0
#!/bin/bash
LINVERC=`lsb_release -a`
BACVERC=`/bin/bash -version`
let LINVER=`echo "$LINVERC"|grep 'Release' |awk -F' ' '{print $2}'|awk -F'.' '{print $1}'`
BACVER=`echo "$BACVERC"|head -1|awk -F' ' '{print $4}'`
echo "$BACVER" > BACVER.log
echo "4.1.2(1)-release" > BACVER6.log
b6=`md5sum BACVER6.log > BACVER6.md5`
echo "3.2.33(1)-release" > BACVER5.log
b5=`md5sum BACVER5.log> BACVER5.md5`
if [ $LINVER -eq 5 ];then
LINST=`echo "$BACVER" > BACVER5.log`
LINST5=` md5sum BACVER5.log >BACVER5.md5`
b5=`md5sum -c --status BACVER5.md5`
st=`echo $?`
if [ $st -eq 0 ];then
echo " linux version is 5 , it is not need update"
else
echo "yum intall 5"
fi
fi
if [ $LINVER -eq 6 ];then
LINST=`echo "$BACVER" > BACVER6.log`
LINST6=`md5sum BACVER6.log >BACVER6.md5`
bc=`md5sum -c --status BACVER6.md5`
st=`echo $?`
if [ $st -eq 0 ];then
echo " linux version is 6 , it is not need update"
else
echo "yum intall 6"
fi
fi
LINVERC=`lsb_release -a`
BACVERC=`/bin/bash -version`
let LINVER=`echo "$LINVERC"|grep 'Release' |awk -F' ' '{print $2}'|awk -F'.' '{print $1}'`
BACVER=`echo "$BACVERC"|head -1|awk -F' ' '{print $4}'`
echo "$BACVER" > BACVER.log
echo "4.1.2(1)-release" > BACVER6.log
b6=`md5sum BACVER6.log > BACVER6.md5`
echo "3.2.33(1)-release" > BACVER5.log
b5=`md5sum BACVER5.log> BACVER5.md5`
if [ $LINVER -eq 5 ];then
LINST=`echo "$BACVER" > BACVER5.log`
LINST5=` md5sum BACVER5.log >BACVER5.md5`
b5=`md5sum -c --status BACVER5.md5`
st=`echo $?`
if [ $st -eq 0 ];then
echo " linux version is 5 , it is not need update"
else
echo "yum intall 5"
fi
fi
if [ $LINVER -eq 6 ];then
LINST=`echo "$BACVER" > BACVER6.log`
LINST6=`md5sum BACVER6.log >BACVER6.md5`
bc=`md5sum -c --status BACVER6.md5`
st=`echo $?`
if [ $st -eq 0 ];then
echo " linux version is 6 , it is not need update"
else
echo "yum intall 6"
fi
fi
0
跑题了,觉得这样交互不错 又简单
#!/bin/bash
linux=`cat /etc/issue`
bash=`rpm -q bash`
echo $linux
echo $bash
read -p "please choose to update or not:" i
case $i in
[qQ]|[Qq][Uu][Ii][Tt])
echo "Bye."
exit
;;
[Nn]|[Nn][Oo])
echo "bash don't need update."
exit
;;
[Yy]|[Yy][Ee][Ss])
/usr/bin/yum update -y bash
;;
esac
exit 0
#!/bin/bash
linux=`cat /etc/issue`
bash=`rpm -q bash`
echo $linux
echo $bash
read -p "please choose to update or not:" i
case $i in
[qQ]|[Qq][Uu][Ii][Tt])
echo "Bye."
exit
;;
[Nn]|[Nn][Oo])
echo "bash don't need update."
exit
;;
[Yy]|[Yy][Ee][Ss])
/usr/bin/yum update -y bash
;;
esac
exit 0
0
#!/bin/bash
#write by 2016-2-1
vv=$(cat /etc/redhat-release|awk '{print $3}'|awk -F "." '{print $1}')
ve=$(rpm -qa|grep bash)
nver=$(echo $ve|awk -F "" '{print $2}'|awk -F ".el" '{print $1}'|sed "s/\.//g" | sed "s/\-//g")
if [ $vv -ge 5 ] && [ $vv -lt 6 ]
then
if [ $nver -gt 3233 ]
then
echo "dont need to update"
else
echo " need to update"
yum update bash
fi
elif [ $vv -ge 6 ] && [ $vv -lt 7 ]
then
if [ $nver -gt 41215 ]
then
echo "dont need to update"
else
echo " need to update"
yum update bash
fi
elif [ $vv -ge ]
then
if [ $nver -gt 42455 ]
then
echo "dont need to update"
else
echo " need to update"
yum update bash
fi
fi
#write by 2016-2-1
vv=$(cat /etc/redhat-release|awk '{print $3}'|awk -F "." '{print $1}')
ve=$(rpm -qa|grep bash)
nver=$(echo $ve|awk -F "" '{print $2}'|awk -F ".el" '{print $1}'|sed "s/\.//g" | sed "s/\-//g")
if [ $vv -ge 5 ] && [ $vv -lt 6 ]
then
if [ $nver -gt 3233 ]
then
echo "dont need to update"
else
echo " need to update"
yum update bash
fi
elif [ $vv -ge 6 ] && [ $vv -lt 7 ]
then
if [ $nver -gt 41215 ]
then
echo "dont need to update"
else
echo " need to update"
yum update bash
fi
elif [ $vv -ge ]
then
if [ $nver -gt 42455 ]
then
echo "dont need to update"
else
echo " need to update"
yum update bash
fi
fi
0
Updating:
bash x86_64 4.1.2-33.el6_7.1 updates 908 k
Transaction Summary
=======================================================================================================================
Upgrade 1 Package(s)
Total download size: 908 k
Is this ok [y/N]: y
Downloading Packages:
bash-4.1.2-33.el6_7.1.x86_64.rpm | 908 kB 00:02
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Updating : bash-4.1.2-33.el6_7.1.x86_64 1/2
Cleanup : bash-4.1.2-29.el6.x86_64 2/2
Verifying : bash-4.1.2-33.el6_7.1.x86_64 1/2
Verifying : bash-4.1.2-29.el6.x86_64 2/2
Updated:
bash.x86_64 0:4.1.2-33.el6_7.1
Complete!
[root@steven ~]# yum update -y bash
bash x86_64 4.1.2-33.el6_7.1 updates 908 k
Transaction Summary
=======================================================================================================================
Upgrade 1 Package(s)
Total download size: 908 k
Is this ok [y/N]: y
Downloading Packages:
bash-4.1.2-33.el6_7.1.x86_64.rpm | 908 kB 00:02
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Updating : bash-4.1.2-33.el6_7.1.x86_64 1/2
Cleanup : bash-4.1.2-29.el6.x86_64 2/2
Verifying : bash-4.1.2-33.el6_7.1.x86_64 1/2
Verifying : bash-4.1.2-29.el6.x86_64 2/2
Updated:
bash.x86_64 0:4.1.2-33.el6_7.1
Complete!
[root@steven ~]# yum update -y bash
0
#!/bin/bash
n=`bash -version|head -1|cut -d' ' -f4`
VERSION=`echo ${n:0:5}`
if [ $VERSION -lt 4.1.2 ];then
yum clean all
yum makecache
yum -y update bash
fi
n=`bash -version|head -1|cut -d' ' -f4`
VERSION=`echo ${n:0:5}`
if [ $VERSION -lt 4.1.2 ];then
yum clean all
yum makecache
yum -y update bash
fi
0
#!/bin/bash
##written by wangyl
##2016=03-18
os_release=`head -1 /etc/issue/ | awk -F'.' '{print $1} | awk -F' ' '{print $3}''`
bash_release=`rpm -q bash|sed 's/.x86_64//;s/.i686//'`
if [ $os_release -eq 5 ] ;then
if [ "$bash_release" != "bash-3.2-33.el5.1" ];then
yum update -y bash
if [ "$bash_release" == "bash-3.2-33.el5.1" ];then
echo "Congratulations to you,the update was successful!" > /tmp/update.log
else
echo "Sorry,the update was failed,please check it out!" > /tmp/update.log
fi
fi
elif [ $os_relsase -eq 6 ];then
if [ "$bash_release" != "bash-4.1.2-15.el6_5.1" ];then
yum update -y bash
if [ "$bash_release" == "bash-4.1.2-15.el6_5.1" ];then
echo "Congratulations to you,the update was successful!" > /tmp/update.log
else
echo "Sorry,the update was failed,please check it out!" > /tmp/update.log
fi
fi
fi
##written by wangyl
##2016=03-18
os_release=`head -1 /etc/issue/ | awk -F'.' '{print $1} | awk -F' ' '{print $3}''`
bash_release=`rpm -q bash|sed 's/.x86_64//;s/.i686//'`
if [ $os_release -eq 5 ] ;then
if [ "$bash_release" != "bash-3.2-33.el5.1" ];then
yum update -y bash
if [ "$bash_release" == "bash-3.2-33.el5.1" ];then
echo "Congratulations to you,the update was successful!" > /tmp/update.log
else
echo "Sorry,the update was failed,please check it out!" > /tmp/update.log
fi
fi
elif [ $os_relsase -eq 6 ];then
if [ "$bash_release" != "bash-4.1.2-15.el6_5.1" ];then
yum update -y bash
if [ "$bash_release" == "bash-4.1.2-15.el6_5.1" ];then
echo "Congratulations to you,the update was successful!" > /tmp/update.log
else
echo "Sorry,the update was failed,please check it out!" > /tmp/update.log
fi
fi
fi
0
#! /bin/bash
linux_version=`cat /etc/centos-release |awk '{print $3}'`
bash_version=`bash --version |head -1 |awk '{print $4}' |awk -F'.' '{print $1$2$3}' |sed 's#(1)-release##g'`
if [ linux_version -lt 6 || bash_version -lt 412]
then
yum update
else
echo "no need to update."
fi
linux_version=`cat /etc/centos-release |awk '{print $3}'`
bash_version=`bash --version |head -1 |awk '{print $4}' |awk -F'.' '{print $1$2$3}' |sed 's#(1)-release##g'`
if [ linux_version -lt 6 || bash_version -lt 412]
then
yum update
else
echo "no need to update."
fi
0
#!/bin/bash
os=`cat /etc/issue|sed -n '1'p|awk '{print $3}'|awk -F '.' '{print $1}'`
ver=`cat /etc/issue|sed -n '1'p|awk '{print $3}'|awk -F '.' '{print $2}'`
bash_v=`rpm -qa bash|awk -F '.' '{OFS="."} {print $1,$2,$3}'`
case $os in
5)
if [ $ver -lt 9 ]
then
/usr/bin/yum -y update >/dev/null 2>&1
else
echo "your linux version $os$ver is the latest one, no need to update"
fi
if [ $bash_v != "bash-3.2-33" ]
then
/usr/bin/yum update -y bash /dev/null 2>&1
else
echo "the bash you installed is latest version $bash_v"
fi
;;
6)
if [ $ver -lt 8 ]
then
/usr/bin/yum -y update /dev/null 2>&1
else
echo "your linux version $os$ver is the latest one, no need to update"
fi
if [ $bash_v != "bash-4.1.2-15" ]
then
/usr/bin/yum update -y bash /dev/null 2>&1
else
echo "the bash you installed is latest version $bash_v"
fi
;;
esac
os=`cat /etc/issue|sed -n '1'p|awk '{print $3}'|awk -F '.' '{print $1}'`
ver=`cat /etc/issue|sed -n '1'p|awk '{print $3}'|awk -F '.' '{print $2}'`
bash_v=`rpm -qa bash|awk -F '.' '{OFS="."} {print $1,$2,$3}'`
case $os in
5)
if [ $ver -lt 9 ]
then
/usr/bin/yum -y update >/dev/null 2>&1
else
echo "your linux version $os$ver is the latest one, no need to update"
fi
if [ $bash_v != "bash-3.2-33" ]
then
/usr/bin/yum update -y bash /dev/null 2>&1
else
echo "the bash you installed is latest version $bash_v"
fi
;;
6)
if [ $ver -lt 8 ]
then
/usr/bin/yum -y update /dev/null 2>&1
else
echo "your linux version $os$ver is the latest one, no need to update"
fi
if [ $bash_v != "bash-4.1.2-15" ]
then
/usr/bin/yum update -y bash /dev/null 2>&1
else
echo "the bash you installed is latest version $bash_v"
fi
;;
esac
0
#!/bin/bash
os=`cat /etc/issue|sed -n '1'p|awk '{print $3}'|awk -F '.' '{print $1}'`
ver=`cat /etc/issue|sed -n '1'p|awk '{print $3}'|awk -F '.' '{print $2}'`
bash_v=`rpm -qa bash|awk -F '.' '{OFS="."} {print $1,$2,$3}'`
case $os in
5)
if [ $ver -lt 9 ]
then
/usr/bin/yum -y update >/dev/null 2>&1
else
echo "your linux version $os$ver is the latest one, no need to update"
fi
if [ $bash_v != "bash-3.2-33" ]
then
/usr/bin/yum update -y bash /dev/null 2>&1
else
echo "the bash you installed is latest version $bash_v"
fi
;;
6)
if [ $ver -lt 8 ]
then
/usr/bin/yum -y update /dev/null 2>&1
else
echo "your linux version $os$ver is the latest one, no need to update"
fi
if [ $bash_v != "bash-4.1.2-15" ]
then
/usr/bin/yum update -y bash /dev/null 2>&1
else
echo "the bash you installed is latest version $bash_v"
fi
;;
esac
os=`cat /etc/issue|sed -n '1'p|awk '{print $3}'|awk -F '.' '{print $1}'`
ver=`cat /etc/issue|sed -n '1'p|awk '{print $3}'|awk -F '.' '{print $2}'`
bash_v=`rpm -qa bash|awk -F '.' '{OFS="."} {print $1,$2,$3}'`
case $os in
5)
if [ $ver -lt 9 ]
then
/usr/bin/yum -y update >/dev/null 2>&1
else
echo "your linux version $os$ver is the latest one, no need to update"
fi
if [ $bash_v != "bash-3.2-33" ]
then
/usr/bin/yum update -y bash /dev/null 2>&1
else
echo "the bash you installed is latest version $bash_v"
fi
;;
6)
if [ $ver -lt 8 ]
then
/usr/bin/yum -y update /dev/null 2>&1
else
echo "your linux version $os$ver is the latest one, no need to update"
fi
if [ $bash_v != "bash-4.1.2-15" ]
then
/usr/bin/yum update -y bash /dev/null 2>&1
else
echo "the bash you installed is latest version $bash_v"
fi
;;
esac
0
#!/bin/bash
a1=`rpm -qa bash|awk -F. '{print $3}'|awk -F- '{print $1}'`
a2=`rpm -qa bash|awk -F. '{print $3}'|awk -F- '{print $2}'`
centos_6 () {
if [ $a1 -lt 2 -o $a2 -lt 15 ]
then
yum update bash
fi
echo "update no " >> /home/shell-10/t.log
}
centos_5 () {
if [ $a1 -lt 2 -o $a2 -lt 33 ]
then
yum update bash
fi
echo "update no " >> /home/shell-10/t.log
}
main () {
v=`uname -r|awk -F. '{print $3}'|awk -F- '{print $1}'`
case $v in
18)
centos_5
;;
32)
centos_6
;;
*)
echo "Centos version is not correct."
esac
}
main
编辑回复