![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Shell 脚本实例
清风的BLOG
专注Linux、Python、自动化、云计算、高可用、数据库。
展开
-
Linux - 分析网站运行状态
1、统计访问网站前十的ip地址awk '{print $1}' | sort | uniq -c | sort -nr | head -10 access_log2、查看某些时间有多少IP访问:{比如2019年10月14日15点一个小时内}awk '{print $4,$1}' log_file | grep 14/Oct/2019:15 | awk '{print $2}' | ...原创 2019-10-14 14:50:15 · 298 阅读 · 0 评论 -
Shell 开发跳板机功能脚本
利用Shell开发跳板机功能脚本案例开发企业级Shell跳板机案例。要求用户登录到跳板机仅能执行管理员给定的选项动作,不允许以任何形式中断脚本到跳板机服务器上执行任何系统命令。1) 首先做好 SSH 密钥验证(跳板机地址:192.168.1.5)下面的命令在所有的机器上操作:[root@jump ~]# useradd zhouhao[root@jump ~]# echo ...原创 2019-10-14 14:25:27 · 466 阅读 · 0 评论 -
Shell脚本 (三)
1、菜单自动化软件部署#!/bin/bashpath=/test[ ! -d "$path" ] && mkdir $path #如果目录不存在,则创建目录cat <<END 1.[install lamp] 2.[install lnmp] 3.[exit] please input y...原创 2019-07-08 16:25:27 · 611 阅读 · 0 评论 -
Shell脚本 (四)
1、实现抓阄脚本#!/bin/bash filelog=/test/zhuajiu.log[ -f "$filelog" ]||touch $filelog #如果不存在日志文件,则创建function check_name(){ #提示用户输入名字函数,判断用户输入是否重复 while true #进入 while 无限循环 do read -p ...原创 2019-07-09 11:12:19 · 798 阅读 · 0 评论 -
Shell脚本(一)
1、批量生成随机字符文件名#!/bin/bash path=/test #定义生产文件的路径[ -d "$path" ] || mkdir -p $path #如果定义的路径不存在则创建for n in `seq 10` # for循环10次,即创建10个文件do random=$(ope...原创 2019-07-04 11:22:08 · 286 阅读 · 0 评论 -
Shell脚本 (五)
1、开发脚本 管理服务端 LVS#!/bin/bash . /etc/init.d/functionsVIP=192.168.1.66INTERFACE=ens33subinterface=${interface}:`echo $vip| cut -d. -f4`PORT=80GW=192.168.1.1RETVAR=0IP=/sbin/ipROUTE=/sbin/...原创 2019-07-10 15:58:12 · 357 阅读 · 0 评论 -
Shell脚本 (二)
1、实现 MySql 分库备份的脚本方法一#!/bin/bash PATH="/usr/local/mysql/bin:$PATH" #定义 mysql 命令所在的路径myuser=root #定义数据库的用户名mypass=123 #定义数据库的密码socket=...原创 2019-07-05 11:25:09 · 222 阅读 · 0 评论 -
Linux中猜数字Shell脚本
[root@test ~]# cat number.sh #!/bin/bash#### define color ####red="3[31m"green="3[32m"yellow="3[33m"color="3[0m"#### check number if conform 1-59 ####check_number(){expr $num1 + 1 #&&...原创 2019-10-11 09:06:05 · 619 阅读 · 0 评论 -
编写可靠Shell脚本的八个建议
1.指定 bashshell 脚本第一行, #!之后应该是什么?回答各不相同./usr/bin/env bash /bin/bash /usr/bin/bash /bin/sh /usr/bin/env sh在大多数情况下,以上五种写法都是等价的,但是,写过程序的人都知道:“少数情况”里往往隐藏着意想不到的坑.如果系统默认 shell 不是 bash ? 怎么办?比如某 l...原创 2019-10-11 10:32:29 · 255 阅读 · 0 评论