目录
多命令执行逻辑
https://blog.csdn.net/u011630575/article/details/97613695
同时执行多条语句
command1 || {
statement1
statement2
statement3
}
if
if如果有else分支,则if分支里必须要执行命令,否则报错。
for
https://blog.csdn.net/weixin_44175418/article/details/124444938
-
文件遍历:
for file in $(ls /opt/control-server/*console.log) do fileDate=${file##*/} fileDate=${fileDate%console*} fileDateSeconds=$(date -d "${fileDate}" +%s) echo "file:${file},fileDateSeconds:${fileDateSeconds}" # 10天之前的日志删除 if [ ${fileDateSeconds} -le $((${curDateSeconds} - 10*24*60*60)) ];then echo "发现过期(超过10天)日志文件${file},删除" sudo rm -f ${file} fi done
-
连续整数遍历
下面是批量开启防火墙端口的代码for port in {9901..9909} do result=$(firewall-cmd --query-port=$port/tcp --zone=public) if [[ "no" = $result ]];then firewall-cmd --permanent --add-port=$port/tcp fi result=$(firewall-cmd --query-port=$port/udp --zone=public) if [[ "no" = $result ]];then firewall-cmd --permanent --add-port=$port/udp fi done
包含子shell文件
http://static.kancloud.cn/dlover/linuxbashshell/2009401
. ./t1.fish #将t1.fish引入
0 条评论