Linux-简-脚本集合
编写脚本,求100以内所有正奇数之和
while加 if 判断
#!/bin/bash
#
#
#
sum=0
i=1
while (($i<=100));do sur=$[i%2]
if [ $sur -eq 0 ];then
let i++
else
let sum+=i
let i++
fi done
echo $sum

编写脚本,打印九九乘法表
for循环
#!/bin/bash
#
#
for ((i=1;i<=9;i++));do
for ((j=1;j<=i;j++));do
printf "${i}x${j}=$[i*j]\t"
done
printf "\n"
done
while循环
#!/bin/bash
#
#
i=1
j=1
while ((i<=9));do
j=1
while ((j<=i));do
printf "${i}x${j}=$[i*j]\t"
let j++
done
let i++
printf "\n"
done

编写脚本,利用变量RANDOM生成10个随机数字,输出这个10数字,并显示其中的最大值和最小值
#!/bin/bash
#
#
min=$RANDOM
max=$min
i=1 while ((i<=10));do
let i++
RD=$RANDOM
echo $RD
if [ $RD -ge $max ];then
max=$RD
else if [ $RD -lt $min ];then
min=$RD
fi
fi
done
echo "maximum is $max"
echo "minimum is $min"

编写脚本 systeminfo.sh,显示当前主机系统信息
#!/bin/bash
#systeminfo
#20220415
# echo
echo "**************************HOST systeminfo*****************************"
echo "HOSTNAME: `hostname`"
echo "IPADDR: `ifconfig |head -2|tail -1|grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}'|head -1`"
echo "OSVERSION: `cat /etc/redhat-release`"
echo "KERNEL: `uname -r`"
echo "CPU: `lscpu | grep "Model name"|tr -s ' '|cut -d":" -f2|head -1`"
echo "MEMORY: `free -h | tr -s ' '|grep Mem|cut -d' ' -f2`"
echo "DISK `lsblk | grep "^sda"|tr -s ' ' | cut -d" " -f4`"
echo "***********************************************************************"

编写脚本disk.sh,显示当前硬盘分区中空间利用率最大的值
#!/bin/bash
#
#Maximum disk space
#USAGE 使用率
#DISKINFO=`df -h | grep "$USAGE"`
USAGE=`df -h |grep -v "Filesystem" |tr -s ' ' |cut -d' ' -f5 |sort -nr|head -1`
DISK=`df -h | grep "$USAGE" | tr -s ' ' | cut -d' ' -f1`
SIZE=`df -h | grep "$USAGE" | tr -s ' ' | cut -d' ' -f2`
USED=`df -h | grep "$USAGE" | tr -s ' ' | cut -d' ' -f3`
AVAIL=`df -h | grep "$USAGE" | tr -s ' ' | cut -d' ' -f4`
FDISK=`df -h | grep "$USAGE" | tr -s ' ' | cut -d' ' -f6`
echo "diskinfo:" #echo "$DISKINFO" echo "$DISK"
echo
echo -e "size:$SIZE; userd:\E[1;31m$USED\E[0m; avail:\E[1;32m$AVAIL\e[0m; use%:\E[1;35m$USAGE\e[0m "
echo
echo -e "\e[1;36mdisk-partition: $DISK\e[0m"
echo "File-directory: $FDISK"

Linux-简-脚本集合的更多相关文章
- linux shell工具集合
1)判断进程是否存在,如果不存在再执行启动命令,可以避免一个脚本同时启动多份 if [ $(ps -ef |grep bastion_account.sh|grep -v grep|wc -l) - ...
- Linux shell脚本学习(一)
一.shell脚本简介 shell脚本是用shell脚本语法将shell命令组织起来形成的文件形式.Shell脚本与Windows/Dos 下的批处理相似,主要为了将大量命令通过一个纯文本文件一次执行 ...
- LINUX SHELL脚本攻略笔记[速查]
Linux Shell脚本攻略笔记[速查] 资源 shell script run shell script echo printf 环境变量和变量 pgrep shell数学运算 命令状态 文件描述 ...
- linux启动脚本
1. linux启动脚本 : /etc/init.d/脚本例如:/etc/init.d/iptables start init.d/ 下面的每一个文件就是一个启动脚本 2. 以上的/etc/init ...
- Linux shell脚本编程(三)
Linux shell脚本编程 流程控制: 循环语句:for,while,until while循环: while CONDITION; do 循环体 done 进入条件:当CONDITION为“真” ...
- Linux shell脚本编程(二)
Linux shell脚本编程(二) 练习:求100以内所有偶数之和; 使用至少三种方法实现; 示例1: #!/bin/bash # declare -i sum=0 #声明一个变量求和,初始值为0 ...
- Linux shell脚本编程(一)
Linux shell脚本编程: 守护进程,服务进程:启动?开机时自动启动: 交互式进程:shell应用程序 广义:GUI,CLI GUI: CLI: 词法分析:命令,选项,参数 内建命令: 外部命令 ...
- Linux Shell 脚本入门
linux shell 脚本格式 #!/bin/sh#..... (注释)命令...命令... 使用vi 创建完成之后需设置权限 chmod +x filename.sh 执行命令: ./filena ...
- Linux Shell脚本入门--cut命令
Linux Shell脚本入门--cut命令 cut cut 命令可以从一个文本文件或者文本流中提取文本列. cut语法 [root@www ~]# cut -d'分隔字符' -f fields &l ...
- Linux Shell脚本攻略 读书笔记
Linux Shell脚本攻略 读书笔记 这是一本小书,总共253页,但内容却很丰富,书中的示例小巧而实用,对我这样总是在shell门前徘徊的人来说真是如获至宝:最有价值的当属文本处理,对这块我单独整 ...
随机推荐
- Ajax的核心的对象是什么?
Ajax的核心对象是XMLXMLHttpRequest 对象. XMLHttpRequest提供不重新加载页面的情况下更新网页,在页面加载后在客户端向服务器请求数据,在页面加载后在服务器端接受数据,在 ...
- 手撕代码之线程:thread类简单使用
转载于:https://blog.csdn.net/qq_22494029/article/details/79273127 简单多线程例子: detch()启动线程: 1 #include < ...
- Docker配置PostgreSQL数据本地持久化
卷的原理图: 主机中的本地目录作为Docker容器内的持久存储卷装载,以便在主机和Docker容器之间共享数据.如果主机希望访问或定期备份在Docker容器内运行的DB服务器写入文件夹的数据或数据库, ...
- 什么是 Spring beans?
Spring beans 是那些形成 Spring 应用的主干的 java 对象.它们被 Spring IOC 容器初始化,装配,和管理.这些 beans 通过容器中配置的元数据创建.比如, 以 XM ...
- IDEA安装配置Scala环境
这里有详细步骤:windows上 IntelliJ IDEA安装scala环境 详细 初学
- 【weex开发】weex官方源码
公司目前使用版本:weex_sdk:0.10.0 介绍地址:https://bintray.com/alibabaweex/maven/weex_sdk/0.18.0 weex最新版本:weex_sd ...
- java中请给出一个return this的例子。
[新手可忽略不影响继续学习]下面例子中setYear中的return this;返回了一个指向对象的指针,this.setMonth(8).setDay(20);是合法的,如果像原来的例子一样什么都不 ...
- DB2表数据导出、导入及常用sql使用总结
一.DB2数据的导出: export to [path(例:D:"TABLE1.ixf)]of ixf select [字段(例: * or col1,col2,col3)] from ...
- Java报错:Error creating bean with name 'testController': Injection of resource dependencies failed
报错如下: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testCo ...
- eBPF Cilium实战(1) - 基于团队的网络隔离
在 Rainbond 集群中,每个团队对应于底层 Kubernetes 的一个 Namespace ,由于之前使用的底层网络无法进行 Namespace 级别的网络管理,所以在 Rainbond 同一 ...