shell脚本常用命令组合
shell 脚本判断linux版本型号
awk -F= '/^NAME/{print $2}' /etc/os-release
centos输出结果
"CentOS Linux"
ubuntu输出结果
"Ubuntu"
============================================
if循环
if [ command ];then
符合该条件执行的语句
elif [ command ];then
符合该条件执行的语句
else
符合该条件执行的语句
fi
=============================================
命令结果=函数
hardDisk=`df -h |grep -w '/'|awk '{ print $5}'| tr -d %`
=============================================
判断一条命令是否有输出
info=`
ls
/dev/mapper/isw_
*`
if
[ -z
"$info"
];
then
echo
"find no fake raid"
else
echo
"yes, find result is $info"
fi
-z判断为空,-n判断是非空
==================================
centos7查看ip
ifconfig |grep -A 1 'ens33:' |tail -1|awk '{print $2}'
===================================
去掉引号内最后一个逗号,当邮件中追加邮件和逗号时,去掉最后一个邮箱的逗号
例:mail_address='1111qq.com,222qq.com,333qq.com,'
sed -i "s/,.$/'/" test.txt
结果:mail_address='1111qq.com,222qq.com,333qq.com'
=====================================