
shell脚本
Jessica丶唯
这个作者很懒,什么都没留下…
展开
-
Shell脚本——一键安装samba服务
要求:写一个shell脚本,能够实现一键安装并配置samba服务,执行该脚本时需要带一个共享的路径,它是共享的目录,目录若存在,需自动创建samba。要求,任何人都可以访问,并且不需要密码,并且是只读的。实验:[root@localhost ~]# vim /opt/samba.sh#!/bin/bashif [ "$#" -ne 1 ]then echo "运行脚本格式为:$0 /dir/"exit 1else if ! echo $1 |grep -q '^/.*'原创 2020-08-27 13:54:20 · 709 阅读 · 0 评论 -
Shell脚本——监控网站是否异常,异常发邮件
要求:写一个shell脚本,通过curl -I 返回状态码来判定所访问的网站是否正常,比如当代码状态200,才算正常写一个发邮件的脚本实验:(1)创建触发器及邮件报警测试[root@localhost ~]# wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz[root@localhost ~]# tar -zxvf sendEmail-v1.56.tar.gzsendEmail-v1.5原创 2020-08-26 14:24:00 · 601 阅读 · 0 评论 -
Shell脚本——自动删除两类机器里面的日志文件
实验要求:两类机器一共300多台,写个脚本自动清理这两类机器里面的日志文件。在堡垒机批量发布,也要批量发布到crontab里面。A类机器日志存放路径很统一,B类机器日志存放路径需要用匹配(因为这个目录里除了日志外,还有其他文件,不能删除。匹配的时候可用.log)A类:/opt/cloud/log/ 删除7天前的B类: /opt/cloud/instances/ 删除15天前的要求写在一个脚本里面。不用考虑堡垒机上的操作,只需要写出shell脚本。[root@localhost ~]# vim原创 2020-08-25 14:24:52 · 1062 阅读 · 2 评论 -
Shell脚本——数组的冒泡排序
[root@localhost ~]# vi maopao.sh#!/bin/basharr=(3 1 5 4 8)a=${#arr[*]}for ((i=1; i<$a; i++))do for ((j=0; j<$a-i; j++)) do if [ ${arr[$j]} -gt ${arr[$[$j + 1]]} ];then temp=${arr[$j]} arr[$j]=${arr[$[$j + 1]]} arr[$[$j+原创 2020-08-23 14:41:24 · 456 阅读 · 0 评论 -
Shell脚本——输出环境变量PATH包含的所有目录以及其中所有可执行文件
方法一:for循环#!/bin/bashIFS=$IFS':'IFS=':'for folder in $PATHdo echo "$folder:" for f in $folder/* do if [ -x $f ];then echo " $f" fi donedone方法二:递归函数(1)#!/bin/bashfile_list () {for f in $1/*do if [ -d $f ];then echo "$2原创 2020-08-23 14:36:26 · 1237 阅读 · 0 评论 -
Shell脚本——1~100之间数字奇数和、偶数和
一、输入一个小于100的整数,并计算从1到该数之间所有整数的和[root@localhost ~]# vi qiuhe.sh#!/bin/bashread -p "请输入小于100的整数:" numif [ $num -eq 1 ];then echo "和等于: $num"sum=0elif [ $num -gt 1 ] && [ $num -lt 100 ];then for ((i=1; i<=$num; i++)) do let sum=$sum+$原创 2020-08-23 14:31:22 · 4498 阅读 · 1 评论 -
Shell脚本——99乘法表和三角形、菱形
一、99乘法表[root@localhost ~]# vim 99.sh#!/bin/bashsum=0for ((a=1; a<=9; a++))do for ((b=1; b<=$a; b++)) do sum=$[$a*$b] echo -ne "$a*$b=$sum\t" doneecho ""done[root@localhost ~]# chmod +x 99.sh [root@localhost ~]# ./99.sh 1*1=1 2*1=原创 2020-08-23 14:18:22 · 609 阅读 · 0 评论