![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
shell脚本类
此专栏主要记录devops实践路上的shell脚本
linus.lin
一个想成为最优秀SRE的骚年
展开
-
shell 脚本之 重启进程
shell 脚本重启进程原创 2022-06-22 20:18:11 · 1767 阅读 · 0 评论 -
shell小技巧
一.读取文件第一行shell命令head -1 file.txt如果用sed来实现,可以是:sed -n ‘1p’ file.txt但上面这个命令会导致整个文件都会读取一遍,对于大数据量的文件效率实在不高。如果能够在读取完了1行之后,就不再读取呢,下面的命令行可以做到:sed -n ‘1p;1q’ file.txt二.查询指定用户名通常想到的方式是:grep 502 /etc/p...原创 2020-01-02 00:10:21 · 426 阅读 · 0 评论 -
shell脚本------系统信息检测---sys-info.sh
#!/bin/bashos_check() { if [ -e /etc/redhat-release ]; then REDHAT=`cat /etc/redhat-release |cut -d' ' -f1` else DEBIAN=`cat /etc/issue |cut -d' ' -f1...原创 2020-01-02 01:38:25 · 455 阅读 · 0 评论 -
shell脚本 ------根据ip查询ip地址
#!/bin/bash# 功能:1.根据ip地址查询所在地# 2.根据文件批量查询所在地,文件中都是一行行的ip地址# 3.根据本机lastb命令查询尝试登陆的ip地址所在地## 适用:centos6+# 语言:中文ipp (){exec < $1while read ado sring=`curl -s "http://i...原创 2020-01-02 01:01:56 · 1021 阅读 · 1 评论 -
shell脚本-------查看cpu温度---cpu-temp.sh
#!/bin/bash# 功能:查看主板上单个多核CPU中温度最高的一个内核# 脚本依赖:lm_sensors工具,可以执行下面语句进行安装,如果安装不了请更换YUM源# 工具安装命令:yum install -y lm_sensors# 注意事项:# 1.“sensors coretemp-isa-0000”中后面的参数视主机实际的参数而定# 2.目前vmware虚拟机中lm_se...原创 2020-01-02 01:15:24 · 2337 阅读 · 3 评论 -
shell脚本---Mysql信息查看_mysql_info.sh
#!/bin/bash# 介绍:mysql_info.sh 信息查看脚本## 注意:适用于5.7版本,其它版本要更改变量hang为2# 功能:查看mysql的信息,用于比对和查询条目数## 适用:centos6+# 语言:中文#all/库名,取最后一个传进来的参数sql_sql=""#从哪行取参数,因为5.7版本有警告信息,所以从第三行取。hang=3#对参数进...原创 2020-01-02 01:18:03 · 644 阅读 · 1 评论 -
shell脚本-------监控网卡信息
#!/bin/bashPATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin;export PATHfunction traffic_monitor { # 系统版本 OS_NAME=$(sed -n '1p' /etc/issue) # 网口名 eth=$1 #判断网卡存在与否,不存在则退出 ...原创 2020-01-02 00:33:47 · 498 阅读 · 1 评论 -
shell脚本-----Mysql全备份----mybak-all.sh
#!/bin/bash# 介绍:mybak-all.sh mysqldump方式全备份脚本## 注意:使用前先测试,并修改对应的变量。# 功能:全备份脚本## 适用:centos6+# 语言:中文##使用:./xx.sh -uroot -p'123456',使用前进行变量配置#过程:备份并刷新binlog,将最新的binlog文件名记录并整体压缩打包#恢复:先进行全量备份,再...原创 2020-01-02 01:21:44 · 339 阅读 · 1 评论 -
shell脚本----javadump
#!/bin/shDUMP_PIDS=`ps --no-heading -C java -f --width 1000 |awk '{print $2}'`if [ -z "$DUMP_PIDS" ]; then echo "The server $HOST_NAME is not started!" exit 1;fiDUMP_ROOT=~/dumpif [ ! -d...原创 2020-01-02 00:22:24 · 279 阅读 · 1 评论 -
按关键字批量杀进程shell脚本
今天,帮同事解决业务问题,中间需要多次按关键字批量杀进程。本着重复三次以上的事情就自动化的原则。写了一个小脚本。可以让同事自助处理脚本如下:#!/bin/bashpids="`ps -ef |grep "$1" |grep -v -e grep -e killkeys |awk '{print $2}'`"if [ -z "$pids" ];then #echo empty exit 0fiecho "kill pid:"$pidskill -9 $pidschmod +x ki原创 2021-07-06 11:41:07 · 504 阅读 · 0 评论 -
shell脚本----Centos 7 一键优化脚本
#!/bin/bash#author junxi by #this script is only for CentOS 7.x#check the OSplatform=`uname -i`if [ $platform != "x86_64" ];then echo "this script is only for 64bit Operating System !"exit 1fi...原创 2020-01-02 00:14:51 · 465 阅读 · 1 评论 -
shell脚本----Mysql增量备份---mybak-section.sh
#!/bin/bash# 介绍:mybak-section.sh 复制Binlog日志方式的增量备份脚本## 注意:执行脚本前修改脚本中的变量# 功能:cp方式增量备份## 适用:centos6+# 语言:中文##使用:./xx.sh -uroot -p'123456',将第一次增量备份后的binlog文件名写到/tmp/binlog-section中,若都没有,自动填写mys...原创 2020-01-02 01:23:43 · 893 阅读 · 1 评论 -
shell脚本------安全监测脚本---safety-check.sh
#!/usr/bin/bash# 1---UID和GID为0的非root特权用户检查newuser_check=`grep "0:0" /etc/passwd | awk -F ':' '{print $1}'`for i in ${newuser_check};do if [[ ${i} != root ]];then echo "警告: 系统存在UID和GID为0...原创 2020-01-02 01:27:32 · 873 阅读 · 0 评论 -
shell脚本--------日志切割
#!/bin/bash# 介绍:logcut.sh 简单的日志切割脚本,前3天的切割方便随时看,前4-10天的进行压缩,超出的删除## 注意:会将其他带时间的日志压缩后删除# 功能:日志切割 <日志格式: xxxxx.当前年-月-日.log> <压缩格式: xxxxx.当前年-月-日.tar.gz>## 适用:centos6+# 语言:中文#流程#主体...原创 2020-01-02 01:09:23 · 2498 阅读 · 1 评论 -
shell脚本-----基线加固脚本---ali-baseline.sh
#!/bin/bashcy() { #检查密码重用是否受限制 if [[ ! -f $1 ]];then echo "$1 not found" exit 1 fi grep 'password' $1 |grep sufficient |grep remember &> /dev/null if [[...原创 2020-01-02 01:40:24 · 1367 阅读 · 3 评论 -
shell脚本------巡检脚本--xunjian1.sh
#!/bin/bash -# 设置检测环境变量。source /etc/profileexport LC_ALL=CTMP_FILE=/tmp/check_tmp_fileCHECK_ID=$(id|sed -e 's/(.*$//' -e 's/^uid=//')if [ $CHECK_ID -ne 0 ]then echo -e "\t你不是root用户!!"exit ...原创 2020-01-02 01:32:08 · 868 阅读 · 1 评论 -
shell脚本----------模拟shell界面---moni-tty.sh
# 介绍:moni-tty.sh 模拟shell界面## 注意:无# 作用:模拟shell界面,可以加入到/etc/profile中,其他人登陆后,看到的都是经过处理的## 适用:centos6+# 语言:英文# 捕获结束信号丢弃,开启后,将无法ctl +c退出#trap "" HUP INT QUIT TSTPclearechocat /etc/system-rel...原创 2020-01-02 01:43:08 · 785 阅读 · 1 评论 -
shell脚本--------显示简单的系统信息
#!/bin/bash# 功能:显示系统信息## 适用:centos6+,ubuntu12+# 语言:中文#[网络部分]net_work=`[[ $(curl -o /dev/null --connect-timeout 3 -s -w "%{http_code}" www.baidu.com) -eq 200 ]] && echo yes || echo no...原创 2020-01-02 00:46:46 · 600 阅读 · 1 评论 -
shell脚本 ----------双向免密脚本--bidfree.sh
#!/bin/bash# 介绍:bid-free.sh 用于hadoop的双向免密脚本,让填写机器互相之间免密登陆## 注意:请勿修改脚本名,需要安装sshpass,也就是需要yum可用# 功能:让填写机器互相之间免密登陆## 适用:centos6+# 语言:中文#[使用设置]#填写所有ip,空格分开ip=(192.168.100.107 192.168.100.113 ...原创 2020-01-02 01:06:01 · 248 阅读 · 0 评论 -
shell脚本--------windows写的文件转换为linux格式
# 介绍:将windows写的文件转换为linux格式## 注意:无# 功能:将单个或者整个文件夹中的文件转换## 适用:centos6+# 语言:中文doss() { yum -y install dos2unix rpm -q dos2unix if [ $? -ne 0 ];then echo "please yum -y ins...原创 2020-01-02 01:11:17 · 3031 阅读 · 1 评论 -
shell脚本------巡检脚本--xunjian2.sh
#!/bin/bash#主机信息每日巡检IPADDR=$(ifconfig eth0|grep 'inet addr'|awk -F '[ :]' '{print $13}')#环境变量PATH没设好,在cron里执行时有很多命令会找不到export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/roo...原创 2020-01-02 01:34:11 · 1612 阅读 · 1 评论