shell脚本编程是linux运维工程师必备的技能,也是非常重要的一个技能,所以把shell编程学好,只有好处.基础语法我也就不讲了,学过C语言这些语言的,稍微看一下就能明白shell编程的基础,所以我们直接切入正题. 开班第20天: 今天的课程大纲: shell编程中的函数 编写一个自动挂载的脚本 利用autofs怎么实现自动挂载 文件锁和信号捕获trap sed流文件编辑器 详细讲解: shell编程中的函数 shell中,我们定义函数的方法有两种: 下面调用的时候,直接调用函数名就可以了…
shell实现多级菜单脚本编写 原文:https://www.yuanmas.com/info/2gOwBPvqyb.html 这篇文章主要介绍了Shell实现多级菜单系统安装脚本实例分享,本文脚本用多级菜单实现LAMP.LNMP安装展现效果,需要的朋友可以参考下: 提示:本脚本主要实现多级菜单效果,并没有安装LAMP.LNMP环境,如果要用在实际生成环境中部署LNMP.LAMP环境,只需要简单修改一下就可以了. 演示效果: 1.一级菜单 2.二级菜单 3.执行操作 脚本参考: 代码如下: #!…
shell编程系列1--shell脚本中的变量替换 变量替换总结: .${变量#匹配规则} # 从头开始匹配,最短删除 .${变量##匹配规则} # 从头开始匹配,最长删除(贪婪模式) .${变量%匹配规则} # 从尾开始匹配,最短删除 .${变量%%匹配规则} # 从尾开始匹配,最长删除(贪婪模式) .${变量/旧字符串/新字符串} # 替换变量内的旧字符串为新字符串,只替换第一个 .${变量//旧字符串/新字符串} # 替换变量内的旧字符串为新字符串,全部替换 variable_1="i l…
Shell脚本 编写Python.PHP脚本通常需要掌握语言的函数,那么Shell脚本则不需要,只需要掌握Linux命令就可以编写Shell脚本,因为Shell脚本就是由多个Linux命令组成,通过将多个Linux命令组合保存成一个脚本文件,可直接给其他人使用. 组合命令 进入一个目录,查看目录的文件,这个过程分别需要执行两条命令,分别是cd 和ls. 分开执行两个命令的形式如下: [root@lincoding usr]# cd /usr/ [root@lincoding usr]# [roo…
编写nginx服务脚本:脚本内容如下: [root@www ~]# cat /etc/init.d/nginx #!/bin/bash # nginx Startup script for the Nginx HTTP Server # chkconfig: - # pidfile: /usr/local/nginx1./logs/nginx.pid # config: /usr/local/nginx1./conf/nginx.conf nginxd=/usr/local/nginx1./sb…
脚本地址 https://github.com/anliven/L-Shell/tree/master/Shell-Basics 示例脚本及注释 主脚本: CallTheScript.sh #!/bin/bash . ./11-subscript.sh # 调用其他脚本;注意点号"."和文件路径之间有一空格; # source ./11-subscript.sh # 调用其他脚本 echo -e ${string} # 使用其他脚本定义的变量 showtest # 使用其他脚本定义的函…
一. 启动脚本模板:符合幂等性 如果该服务已经启动,再次调用该脚本,不会报错,也就是说可以反复多次调用,另外启动成功返回 一个参数,提供给自动发布平台校验该服务是否启动 #!/bin/bash instancename= # check is instance running PID=`ps -ef | $instancename | grep -v grep ` if [ ! -z "$PID" ]; then echo "instance $instancename is…
1创建文本菜单 1.1普通的文本菜单 $ cat menu1 #!/bin/bash # simple script menu function diskspace { clear df -k } function whoseon { clear who } function memusage { clear cat /proc/meminfo } function memu{ clear echo echo -e "\t\t\tSys Admin Menu\n" echo -e &q…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 8…
nginx_daemon.sh #!/bin/bash # this_pid=$$ while true do ps -ef | grep nginx | grep -v grep | grep -v $this_pid &> /dev/null ];then echo "nginx is ok" else systemctl start nginx echo "nginx is down,starting it..." fi done 执行脚本 后台…